| Line 42... |
Line 42... |
| 42 |
import com.spice.profitmandi.service.NotificationService;
|
42 |
import com.spice.profitmandi.service.NotificationService;
|
| 43 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
43 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 44 |
import com.spice.profitmandi.service.integrations.bharti.model.PlanVariant;
|
44 |
import com.spice.profitmandi.service.integrations.bharti.model.PlanVariant;
|
| 45 |
import com.spice.profitmandi.service.integrations.icicilombard.IciciLombardService;
|
45 |
import com.spice.profitmandi.service.integrations.icicilombard.IciciLombardService;
|
| 46 |
import com.spice.profitmandi.service.integrations.icicilombard.model.AfinityQuoteModel;
|
46 |
import com.spice.profitmandi.service.integrations.icicilombard.model.AfinityQuoteModel;
|
| - |
|
47 |
import com.spice.profitmandi.service.integrations.icicilombard.model.AfinityQuoteResponseModel;
|
| 47 |
import com.spice.profitmandi.service.integrations.zest.InsuranceService;
|
48 |
import com.spice.profitmandi.service.integrations.zest.InsuranceService;
|
| 48 |
import com.spice.profitmandi.service.integrations.zest.MobileInsurancePlan;
|
49 |
import com.spice.profitmandi.service.integrations.zest.MobileInsurancePlan;
|
| 49 |
import com.spice.profitmandi.service.order.BulkOrderService;
|
50 |
import com.spice.profitmandi.service.order.BulkOrderService;
|
| 50 |
import com.spice.profitmandi.service.order.OrderService;
|
51 |
import com.spice.profitmandi.service.order.OrderService;
|
| 51 |
import com.spice.profitmandi.service.pricing.PricingService;
|
52 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| Line 76... |
Line 77... |
| 76 |
import org.springframework.web.multipart.MultipartFile;
|
77 |
import org.springframework.web.multipart.MultipartFile;
|
| 77 |
|
78 |
|
| 78 |
import javax.mail.MessagingException;
|
79 |
import javax.mail.MessagingException;
|
| 79 |
import javax.servlet.http.HttpServletRequest;
|
80 |
import javax.servlet.http.HttpServletRequest;
|
| 80 |
import javax.servlet.http.HttpServletResponse;
|
81 |
import javax.servlet.http.HttpServletResponse;
|
| 81 |
import java.io.ByteArrayInputStream;
|
- |
|
| 82 |
import java.io.ByteArrayOutputStream;
|
- |
|
| 83 |
import java.io.IOException;
|
82 |
import java.io.*;
|
| 84 |
import java.io.InputStream;
|
- |
|
| 85 |
import java.nio.charset.StandardCharsets;
|
83 |
import java.nio.charset.StandardCharsets;
|
| - |
|
84 |
import java.nio.file.Files;
|
| 86 |
import java.time.LocalDate;
|
85 |
import java.time.LocalDate;
|
| 87 |
import java.time.LocalDateTime;
|
86 |
import java.time.LocalDateTime;
|
| 88 |
import java.time.format.DateTimeFormatter;
|
87 |
import java.time.format.DateTimeFormatter;
|
| 89 |
import java.time.temporal.ChronoUnit;
|
88 |
import java.time.temporal.ChronoUnit;
|
| 90 |
import java.util.*;
|
89 |
import java.util.*;
|
| Line 582... |
Line 581... |
| 582 |
String itemBrand = itemRepository.selectById(itemId).getBrand();
|
581 |
String itemBrand = itemRepository.selectById(itemId).getBrand();
|
| 583 |
|
582 |
|
| 584 |
AfinityQuoteModel quoteModel = new AfinityQuoteModel();
|
583 |
AfinityQuoteModel quoteModel = new AfinityQuoteModel();
|
| 585 |
quoteModel.setPolicyStartDate(today.toString()); // format: yyyy-MM-dd
|
584 |
quoteModel.setPolicyStartDate(today.toString()); // format: yyyy-MM-dd
|
| 586 |
quoteModel.setPolicyEndDate(oneYearLater.toString());
|
585 |
quoteModel.setPolicyEndDate(oneYearLater.toString());
|
| 587 |
quoteModel.setPlanCode(String.valueOf(planVariant.getOurPlanId()));
|
586 |
// quoteModel.setPlanCode(String.valueOf(planVariant.getOurPlanId()));
|
| - |
|
587 |
quoteModel.setPlanCode(String.valueOf(10357));
|
| 588 |
quoteModel.setSumInsured((int) sumInsured);
|
588 |
quoteModel.setSumInsured((int) sumInsured);
|
| 589 |
quoteModel.setBasisOfValuation("Market_Value");
|
589 |
quoteModel.setBasisOfValuation("Market_Value");
|
| 590 |
quoteModel.setPartyStateName("MUMBAI");
|
590 |
quoteModel.setPartyStateName(iciciLombardService.PARTY_STATE_NAME);
|
| 591 |
quoteModel.setRiskSIComponent("MOBILE");
|
591 |
quoteModel.setRiskSIComponent("MOBILE");
|
| 592 |
quoteModel.setMakeManufacturer(itemBrand.toUpperCase());
|
592 |
quoteModel.setMakeManufacturer(itemBrand.toUpperCase());
|
| 593 |
quoteModel.setYearOfManufacture(manufactured.getYear());
|
593 |
quoteModel.setYearOfManufacture(manufactured.getYear());
|
| 594 |
quoteModel.setCoverName("All Risk");
|
594 |
quoteModel.setCoverName("All Risk");
|
| 595 |
quoteModel.setCorrelationId(correlationId);
|
595 |
quoteModel.setCorrelationId(correlationId);
|
| 596 |
|
596 |
|
| 597 |
String response = mvcResponseSender.createResponseString(iciciLombardService.hitAfinityQuote(quoteModel));
|
597 |
AfinityQuoteResponseModel afinityQuoteResponseModel = iciciLombardService.hitAfinityQuote(quoteModel);
|
| - |
|
598 |
float planDp = insuranceService.getPlanDp(afinityQuoteResponseModel.getTotalPremium(), planVariant.getCoverage());
|
| - |
|
599 |
|
| 598 |
LOGGER.info("response {}",response);
|
600 |
Map<String, Object> responseMap = new HashMap<>();
|
| - |
|
601 |
responseMap.put("afinityQuoteModel", afinityQuoteResponseModel);
|
| - |
|
602 |
responseMap.put("planDp", planDp);
|
| 599 |
model.addAttribute("response1", response);
|
603 |
model.addAttribute("response1", mvcResponseSender.createResponseString(responseMap));
|
| 600 |
} catch (Exception e) {
|
604 |
} catch (Exception e) {
|
| 601 |
// TODO Auto-generated catch block
|
605 |
// TODO Auto-generated catch block
|
| 602 |
LOGGER.info(e.getMessage(), e);
|
606 |
LOGGER.info(e.getMessage(), e);
|
| 603 |
throw new ProfitMandiBusinessException("Plans", "Plans Quote", "Error qutotation insurance plans");
|
607 |
throw new ProfitMandiBusinessException("Plans", "Plans Quote", "Error qutotation insurance plans");
|
| 604 |
}
|
608 |
}
|
| Line 719... |
Line 723... |
| 719 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
723 |
if (roleManager.isAdmin(fofoDetails.getRoleIds())) {
|
| 720 |
pdfModel = orderService.getInvoicePdfModel(orderId);
|
724 |
pdfModel = orderService.getInvoicePdfModel(orderId);
|
| 721 |
} else {
|
725 |
} else {
|
| 722 |
pdfModel = orderService.getInvoicePdfModel(fofoDetails.getFofoId(), orderId);
|
726 |
pdfModel = orderService.getInvoicePdfModel(fofoDetails.getFofoId(), orderId);
|
| 723 |
}
|
727 |
}
|
| - |
|
728 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(orderId);
|
| - |
|
729 |
List<InsurancePolicy> insurancePolicies = insurancePolicyRepository.selectByRetailerIdInvoiceNumber(fofoOrder.getInvoiceNumber());
|
| - |
|
730 |
|
| - |
|
731 |
// Step 1: Generate invoice PDF
|
| 724 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
732 |
ByteArrayOutputStream invoiceOutput = new ByteArrayOutputStream();
|
| 725 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
|
733 |
PdfUtils.generateAndWrite(Arrays.asList(pdfModel), invoiceOutput);
|
| 726 |
LOGGER.info("Pdf Stream length {}", byteArrayOutputStream.toByteArray().length);
|
734 |
byte[] invoicePdf = invoiceOutput.toByteArray();
|
| - |
|
735 |
|
| - |
|
736 |
// Step 2: Load all policy certificate PDFs
|
| - |
|
737 |
List<byte[]> pdfFiles = new ArrayList<>();
|
| - |
|
738 |
pdfFiles.add(invoicePdf); // first add invoice
|
| - |
|
739 |
|
| - |
|
740 |
for (InsurancePolicy insurancePolicy : insurancePolicies) {
|
| - |
|
741 |
String policyNumber = insurancePolicy.getPolicyNumber();
|
| - |
|
742 |
String safePolicyNo = policyNumber.replace("/", "-");
|
| - |
|
743 |
String filePath = "/Users/amit/uploads/policy-certificate-" + safePolicyNo + ".pdf";
|
| - |
|
744 |
File file = new File(filePath);
|
| - |
|
745 |
|
| - |
|
746 |
if (file.exists()) {
|
| - |
|
747 |
try {
|
| - |
|
748 |
byte[] policyPdf = Files.readAllBytes(file.toPath());
|
| - |
|
749 |
pdfFiles.add(policyPdf);
|
| - |
|
750 |
} catch (IOException e) {
|
| - |
|
751 |
LOGGER.error("Failed to read policy PDF: {}", filePath, e);
|
| - |
|
752 |
}
|
| - |
|
753 |
} else {
|
| - |
|
754 |
LOGGER.warn("Policy PDF not found: {}", filePath);
|
| - |
|
755 |
}
|
| - |
|
756 |
}
|
| - |
|
757 |
|
| - |
|
758 |
// Step 3: Merge all PDFs
|
| - |
|
759 |
byte[] mergedPdf;
|
| - |
|
760 |
try {
|
| - |
|
761 |
mergedPdf = PdfUtils.mergePdfFiles(pdfFiles);
|
| - |
|
762 |
} catch (Exception e) {
|
| - |
|
763 |
LOGGER.error("Error merging PDFs", e);
|
| - |
|
764 |
throw new ProfitMandiBusinessException("Failed to generate merged PDF", "", "");
|
| - |
|
765 |
}
|
| - |
|
766 |
|
| - |
|
767 |
// Step 4: Return merged PDF as response
|
| 727 |
final HttpHeaders headers = new HttpHeaders();
|
768 |
HttpHeaders headers = new HttpHeaders();
|
| 728 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
769 |
headers.setContentType(MediaType.APPLICATION_PDF);
|
| 729 |
headers.setContentDispositionFormData("inline", "invoice-" + pdfModel.getInvoiceNumber() + ".pdf");
|
770 |
headers.setContentDispositionFormData("inline", "invoice-with-policies-" + pdfModel.getInvoiceNumber() + ".pdf");
|
| 730 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
771 |
headers.setContentLength(mergedPdf.length);
|
| 731 |
final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
- |
|
| - |
|
772 |
|
| 732 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
773 |
InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(mergedPdf));
|
| 733 |
return new ResponseEntity<>(inputStreamResource, headers, HttpStatus.OK);
|
774 |
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
|
| 734 |
}
|
775 |
}
|
| 735 |
|
776 |
|
| 736 |
@RequestMapping(value = "/generateInvoices")
|
777 |
@RequestMapping(value = "/generateInvoices")
|
| 737 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
778 |
public ResponseEntity<?> generateInvoice(HttpServletRequest request, HttpServletResponse response,
|
| 738 |
@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, @RequestParam int partnerId)
|
779 |
@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, @RequestParam int partnerId)
|