diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-client/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/client/v1/CirrasUnderwritingService.java b/cirras-underwriting-api/cirras-underwriting-api-rest-client/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/client/v1/CirrasUnderwritingService.java index 87353ca6..3e1996e4 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-client/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/client/v1/CirrasUnderwritingService.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-client/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/client/v1/CirrasUnderwritingService.java @@ -146,7 +146,8 @@ byte[] generateInventoryReport( String policyNumber, String growerInfo, String sortColumn, - String policyIds + String policyIds, + String reportType ) throws CirrasUnderwritingServiceException; diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-client/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/client/v1/impl/CirrasUnderwritingServiceImpl.java b/cirras-underwriting-api/cirras-underwriting-api-rest-client/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/client/v1/impl/CirrasUnderwritingServiceImpl.java index b0b8c7f8..0fe08a34 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-client/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/client/v1/impl/CirrasUnderwritingServiceImpl.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-client/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/client/v1/impl/CirrasUnderwritingServiceImpl.java @@ -460,7 +460,8 @@ public byte[] generateInventoryReport( String policyNumber, String growerInfo, String sortColumn, - String policyIds) throws CirrasUnderwritingServiceException { + String policyIds, + String reportType) throws CirrasUnderwritingServiceException { GenericRestDAO dao = this.getRestDAOFactory().getGenericRestDAO(byte[].class); @@ -474,6 +475,7 @@ public byte[] generateInventoryReport( putQueryParam(queryParams, "growerInfo", growerInfo); putQueryParam(queryParams, "sortColumn", sortColumn); putQueryParam(queryParams, "policyIds", policyIds); + putQueryParam(queryParams, "reportType", reportType); Response response = dao.Process(ResourceTypes.BYTES, new NullTransformer("application/octet-stream", "bytes"), parent, queryParams, getWebClient()); diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-common/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/VerifiedYieldContractRsrc.java b/cirras-underwriting-api/cirras-underwriting-api-rest-common/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/VerifiedYieldContractRsrc.java index 67cd6ae1..d4dccb42 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-common/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/VerifiedYieldContractRsrc.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-common/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/VerifiedYieldContractRsrc.java @@ -14,11 +14,12 @@ import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContract; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContractCommodity; import ca.bc.gov.nrs.common.wfone.rest.resource.BaseResource; +import ca.bc.gov.nrs.common.wfone.rest.resource.MessageRsrc; @XmlRootElement(namespace = ResourceTypes.NAMESPACE, name = ResourceTypes.VERIFIED_YIELD_CONTRACT_NAME) @XmlSeeAlso({ VerifiedYieldContractRsrc.class }) @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "@type") -public class VerifiedYieldContractRsrc extends BaseResource implements VerifiedYieldContract { +public class VerifiedYieldContractRsrc extends BaseResource implements VerifiedYieldContract { private static final long serialVersionUID = 1L; @@ -32,10 +33,12 @@ public class VerifiedYieldContractRsrc extends BaseResource implements VerifiedY private Integer insurancePlanId; private Integer growerContractYearId; + private Boolean updateProductValuesInd; private List fields = new ArrayList(); private List verifiedYieldContractCommodities = new ArrayList(); private List verifiedYieldAmendments = new ArrayList(); + private List productWarningMessages = new ArrayList(); public String getVerifiedYieldContractGuid() { return verifiedYieldContractGuid; @@ -100,6 +103,14 @@ public void setGrowerContractYearId(Integer growerContractYearId) { this.growerContractYearId = growerContractYearId; } + public Boolean getUpdateProductValuesInd() { + return updateProductValuesInd; + } + + public void setUpdateProductValuesInd(Boolean updateProductValuesInd) { + this.updateProductValuesInd = updateProductValuesInd; + } + public List getFields() { return fields; } @@ -121,4 +132,11 @@ public void setVerifiedYieldAmendments(List verifiedYiel this.verifiedYieldAmendments = verifiedYieldAmendments; } + public List getProductWarningMessages() { + return productWarningMessages; + } + public void setProductWarningMessages(List productWarningMessages) { + this.productWarningMessages = productWarningMessages; + } + } diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/InventoryContractReportEndpoint.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/InventoryContractReportEndpoint.java index e8c40e48..caf97274 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/InventoryContractReportEndpoint.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/InventoryContractReportEndpoint.java @@ -49,7 +49,8 @@ Response generateInventoryReport( @Parameter(description = "Filter the results by the policy number") @QueryParam("policyNumber") String policyNumber, @Parameter(description = "Filter the results by the grower info (Name, Number, Phone, Email") @QueryParam("growerInfo") String growerInfo, @Parameter(description = "Sort by column") @QueryParam("sortColumn") String sortColumn, - @Parameter(description = "IDs of policies to be included") @QueryParam("policyIds") String policyIds + @Parameter(description = "IDs of policies to be included") @QueryParam("policyIds") String policyIds, + @Parameter(description = "Type of report: unseeded or seeded (GRAIN only)") @QueryParam("reportType") String reportType ); } diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/impl/InventoryContractReportEndpointImpl.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/impl/InventoryContractReportEndpointImpl.java index e2f0bf7b..af3874f1 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/impl/InventoryContractReportEndpointImpl.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/impl/InventoryContractReportEndpointImpl.java @@ -39,7 +39,8 @@ public Response generateInventoryReport( String policyNumber, String growerInfo, String sortColumn, - String policyIds) { + String policyIds, + String reportType) { Response response = null; @@ -69,6 +70,7 @@ public Response generateInventoryReport( toString(growerInfo), toString(sortColumn), toString(policyIds), + toString(reportType), getFactoryContext(), getWebAdeAuthentication()); diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/VerifiedYieldContractRsrcFactory.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/VerifiedYieldContractRsrcFactory.java index 99852831..90b6852d 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/VerifiedYieldContractRsrcFactory.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/main/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/resource/factory/VerifiedYieldContractRsrcFactory.java @@ -1,6 +1,8 @@ package ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.factory; +import ca.bc.gov.nrs.common.wfone.rest.resource.MessageRsrc; import ca.bc.gov.nrs.common.wfone.rest.resource.RelLink; +import ca.bc.gov.nrs.wfone.common.model.Message; import ca.bc.gov.nrs.wfone.common.rest.endpoints.resource.factory.BaseResourceFactory; import ca.bc.gov.nrs.wfone.common.service.api.model.factory.FactoryContext; import ca.bc.gov.nrs.wfone.common.service.api.model.factory.FactoryException; @@ -8,10 +10,14 @@ import java.net.URI; import java.util.ArrayList; +import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import javax.ws.rs.core.UriBuilder; @@ -32,18 +38,21 @@ import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.InventoryFieldDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.InventorySeededGrainDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.PolicyDto; +import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.ProductDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldAmendmentDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldContractCommodityDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldContractDto; import ca.bc.gov.mal.cirras.underwriting.service.api.v1.model.factory.VerifiedYieldContractFactory; +import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.CommodityCoverageCode; import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.InventoryServiceEnums.InsurancePlans; public class VerifiedYieldContractRsrcFactory extends BaseResourceFactory implements VerifiedYieldContractFactory { @Override - public VerifiedYieldContract getDefaultVerifiedYieldContract( + public VerifiedYieldContract getDefaultVerifiedYieldContract( PolicyDto policyDto, DeclaredYieldContractDto dycDto, + List productDtos, FactoryContext context, WebAdeAuthentication authentication ) throws FactoryException { @@ -69,7 +78,7 @@ public VerifiedYieldContract getDefaultVerifiedYieldContr List vyContractCommodities = new ArrayList(); for (DeclaredYieldContractCommodityDto dyccDto : dycDto.getDeclaredYieldContractCommodities()) { - VerifiedYieldContractCommodity vyccModel = createDefaultVerifiedYieldContractCommodity(dyccDto); + VerifiedYieldContractCommodity vyccModel = createDefaultVerifiedYieldContractCommodity(dyccDto, productDtos); vyContractCommodities.add(vyccModel); } @@ -93,11 +102,19 @@ private void populateDefaultResource(VerifiedYieldContractRsrc resource, PolicyD resource.setVerifiedYieldContractGuid(null); resource.setVerifiedYieldUpdateTimestamp(null); resource.setVerifiedYieldUpdateUser(null); + resource.setProductWarningMessages(new ArrayList()); } - private VerifiedYieldContractCommodity createDefaultVerifiedYieldContractCommodity(DeclaredYieldContractCommodityDto dto) { + private VerifiedYieldContractCommodity createDefaultVerifiedYieldContractCommodity(DeclaredYieldContractCommodityDto dto, List productDtos) { VerifiedYieldContractCommodity model = new VerifiedYieldContractCommodity(); + + //Get production guarantee + Double productionGuarantee = null; + ProductDto product = getProductDto(dto.getCropCommodityId(), dto.getIsPedigreeInd(), productDtos); + if(product != null && product.getProductStatusCode().equals(PRODUCT_STATUS_FINAL)) { + productionGuarantee = product.getProductionGuarantee(); + } model.setCropCommodityId(dto.getCropCommodityId()); model.setCropCommodityName(dto.getCropCommodityName()); @@ -106,7 +123,7 @@ private VerifiedYieldContractCommodity createDefaultVerifiedYieldContractCommodi model.setHarvestedYield(null); // Calculated later model.setHarvestedYieldOverride(null); model.setIsPedigreeInd(dto.getIsPedigreeInd()); - model.setProductionGuarantee(null); // TODO: Will be implemented later. + model.setProductionGuarantee(productionGuarantee); model.setSoldYieldDefaultUnit(dto.getSoldYieldDefaultUnit()); model.setStoredYieldDefaultUnit(dto.getStoredYieldDefaultUnit()); model.setTotalInsuredAcres(dto.getTotalInsuredAcres()); @@ -118,7 +135,7 @@ private VerifiedYieldContractCommodity createDefaultVerifiedYieldContractCommodi } @Override - public VerifiedYieldContract getVerifiedYieldContract(VerifiedYieldContractDto dto, + public VerifiedYieldContract getVerifiedYieldContract(VerifiedYieldContractDto dto, List productDtos, FactoryContext context, WebAdeAuthentication authentication) throws FactoryException { VerifiedYieldContractRsrc resource = new VerifiedYieldContractRsrc(); @@ -137,6 +154,8 @@ public VerifiedYieldContract getVerifiedYieldContract(Ver resource.setFields(fields); } + List productWarnings = new ArrayList(); + // Verified Yield Contract Commodity if (!dto.getVerifiedYieldContractCommodities().isEmpty()) { List verifiedContractCommodities = new ArrayList(); @@ -144,6 +163,12 @@ public VerifiedYieldContract getVerifiedYieldContract(Ver for (VerifiedYieldContractCommodityDto vyccDto : dto.getVerifiedYieldContractCommodities()) { VerifiedYieldContractCommodity vyccModel = createVerifiedYieldContractCommodity(vyccDto); verifiedContractCommodities.add(vyccModel); + + //Check product guarantee + MessageRsrc warning = getProductWarning(vyccDto, productDtos); + if(warning != null) { + productWarnings.add(warning); + } } resource.setVerifiedYieldContractCommodities(verifiedContractCommodities); @@ -161,6 +186,8 @@ public VerifiedYieldContract getVerifiedYieldContract(Ver resource.setVerifiedYieldAmendments(verifiedYieldAmendments); } + resource.setProductWarningMessages(productWarnings); + String eTag = getEtag(resource); resource.setETag(eTag); @@ -182,8 +209,87 @@ private void populateResource(VerifiedYieldContractRsrc resource, VerifiedYieldC resource.setVerifiedYieldContractGuid(dto.getVerifiedYieldContractGuid()); resource.setVerifiedYieldUpdateTimestamp(dto.getVerifiedYieldUpdateTimestamp()); resource.setVerifiedYieldUpdateUser(dto.getVerifiedYieldUpdateUser()); + resource.setUpdateProductValuesInd(false); } + + public static final String PRODUCT_STATUS_FINAL = "FINAL"; + public static final String PRODUCTION_GUARANTEE_DIFFERENCE_MSG = "Production guarantee for %s is different in the product: %.2f"; + public static final String PRODUCTION_GUARANTEE_NONE_MSG = "There is no production guarantee for %s"; + public static final String PRODUCTION_GUARANTEE_NO_PRODUCT_MSG = "There is no product for %s in CIRRAS. The shown Production guarantee is not valid anymore."; + + private MessageRsrc getProductWarning(VerifiedYieldContractCommodityDto vyccDto, List productDtos) { + + MessageRsrc messageRsrc = null; + + //Find product + ProductDto product = getProductDto(vyccDto.getCropCommodityId(), vyccDto.getIsPedigreeInd(), productDtos); + + if(product != null) { + if(product.getProductStatusCode().equals(PRODUCT_STATUS_FINAL)) { + if (Double.compare(notNull(product.getProductionGuarantee(), (double)-1), notNull(vyccDto.getProductionGuarantee(), (double)-1)) != 0) { + //Add warning if values are different -> Only if product is in status FINAL + String commodity = vyccDto.getCropCommodityName(); + if(vyccDto.getIsPedigreeInd()) { + commodity = commodity + " Pedigreed"; + } + + String msg = ""; + if(product.getProductionGuarantee() == null) { + msg = String.format(PRODUCTION_GUARANTEE_NONE_MSG, commodity, product.getProductionGuarantee()); + } else { + msg = String.format(PRODUCTION_GUARANTEE_DIFFERENCE_MSG, commodity, product.getProductionGuarantee()); + } + + messageRsrc = new MessageRsrc(msg); + } + } + } else { + //No product: Check if the production guarantee in commodity totals is null + if(vyccDto.getProductionGuarantee() != null) { + //Add warning if there is no product but a saved production guarantee + String commodity = vyccDto.getCropCommodityName(); + if(vyccDto.getIsPedigreeInd()) { + commodity = commodity + " Pedigreed"; + } + + String msg = String.format(PRODUCTION_GUARANTEE_NO_PRODUCT_MSG, commodity); + messageRsrc = new MessageRsrc(msg); + } + } + + + return messageRsrc; + } + + private static final Set coverageCodes = new HashSet(Arrays.asList( + new String[] { + CommodityCoverageCode.QUANTITY_GRAIN, + CommodityCoverageCode.QUANTITY_FORAGE, + CommodityCoverageCode.QUANTITY_SILAGE_CORN + })); + + private ProductDto getProductDto(Integer cropCommodityId, Boolean isPedigree, List productDtos) { + + ProductDto product = null; + + if(productDtos != null && productDtos.size() > 0) { + //Products in CIRRAS use a different commodity id for pedigreed than in this app. A table maps the correct commodity ids and + //are returned to the NonPedigreeCropCommodityId property + List products = productDtos.stream() + .filter(x -> x.getNonPedigreeCropCommodityId().equals(cropCommodityId) + && x.getIsPedigreeProduct().equals(isPedigree) + && coverageCodes.contains(x.getCommodityCoverageCode())) + .collect(Collectors.toList()); + + if (products != null && products.size() > 0) { + product = products.get(0); + } + } + + + return product; + } private VerifiedYieldContractCommodity createVerifiedYieldContractCommodity(VerifiedYieldContractCommodityDto dto) { VerifiedYieldContractCommodity model = new VerifiedYieldContractCommodity(); @@ -314,7 +420,7 @@ private static void setLinks(String verifiedYieldContractGuid, VerifiedYieldCont } @Override - public void updateDto(VerifiedYieldContractDto dto, VerifiedYieldContract model, String userId) { + public void updateDto(VerifiedYieldContractDto dto, VerifiedYieldContract model, String userId) { dto.setVerifiedYieldContractGuid(model.getVerifiedYieldContractGuid()); dto.setContractId(model.getContractId()); @@ -329,7 +435,22 @@ public void updateDto(VerifiedYieldContractDto dto, VerifiedYieldContract productDtos, + Boolean updateProductValues) { + + Double productionGuarantee = model.getProductionGuarantee(); + //Get production guarantee if user wants to update the values + if(Boolean.TRUE.equals(updateProductValues)) { + ProductDto product = getProductDto(dto.getCropCommodityId(), dto.getIsPedigreeInd(), productDtos); + if(product != null && product.getProductStatusCode().equals(PRODUCT_STATUS_FINAL)) { + productionGuarantee = product.getProductionGuarantee(); + } else { + productionGuarantee = null; + } + } dto.setVerifiedYieldContractCommodityGuid(model.getVerifiedYieldContractCommodityGuid()); dto.setVerifiedYieldContractGuid(model.getVerifiedYieldContractGuid()); @@ -339,11 +460,14 @@ public void updateDto(VerifiedYieldContractCommodityDto dto, VerifiedYieldContra dto.setHarvestedAcresOverride(model.getHarvestedAcresOverride()); dto.setStoredYieldDefaultUnit(model.getStoredYieldDefaultUnit()); dto.setSoldYieldDefaultUnit(model.getSoldYieldDefaultUnit()); - dto.setProductionGuarantee(model.getProductionGuarantee()); + dto.setProductionGuarantee(productionGuarantee); dto.setHarvestedYield(model.getHarvestedYield()); dto.setHarvestedYieldOverride(model.getHarvestedYieldOverride()); dto.setYieldPerAcre(model.getYieldPerAcre()); } - + + private Double notNull(Double value, Double defaultValue) { + return (value == null) ? defaultValue : value; + } } diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/InventoryContractEndpointForageTest.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/InventoryContractEndpointForageTest.java index 1066518f..389edc95 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/InventoryContractEndpointForageTest.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/InventoryContractEndpointForageTest.java @@ -12,6 +12,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.InventoryServiceEnums.InventoryReportType; import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.LandManagementEventTypes; import ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.PoliciesSyncEventTypes; import ca.bc.gov.mal.cirras.underwriting.api.rest.client.v1.CirrasUnderwritingService; @@ -630,34 +631,57 @@ public void testGenerateInventoryReport() throws CirrasUnderwritingServiceExcept } // Test 1: Generate Forage report. - byte[] reportContent = service.generateInventoryReport(topLevelEndpoints, "2023", "5", null, null, null, null, null, null); + byte[] reportContent = service.generateInventoryReport(topLevelEndpoints, "2023", "5", null, null, null, null, null, null, null); Assert.assertNotNull(reportContent); logger.debug(">testGenerateInventoryReport - Returned " + reportContent.length + " bytes"); - // Test 2: Generate Grain report - reportContent = service.generateInventoryReport(topLevelEndpoints, "2023", "4", null, null, null, null, null, null); + // Test 2: Generate Grain Unseeded report + reportContent = service.generateInventoryReport(topLevelEndpoints, "2023", "4", null, null, null, null, null, null, InventoryReportType.unseeded.name()); Assert.assertNotNull(reportContent); logger.debug(">testGenerateInventoryReport - Returned " + reportContent.length + " bytes"); + + // Test 3: Generate Grain Seeded report + reportContent = service.generateInventoryReport(topLevelEndpoints, "2023", "4", null, null, null, null, null, null, InventoryReportType.seeded.name()); + + Assert.assertNotNull(reportContent); + + logger.debug(">testGenerateInventoryReport - Returned " + reportContent.length + " bytes"); - // Test 3: Omit Insurance Plan: Report generation should fail. + // Test 4: Omit Insurance Plan: Report generation should fail. try { - reportContent = service.generateInventoryReport(topLevelEndpoints, "2023", null, null, null, null, null, null, null); + reportContent = service.generateInventoryReport(topLevelEndpoints, "2023", null, null, null, null, null, null, null, null); Assert.fail("Report generated for missing insurance plan id "); } catch ( CirrasUnderwritingServiceException e ) { // Ok. } - // Test 4: Invalid Insurance Plan: Report generation should fail. + // Test 5: Invalid Insurance Plan: Report generation should fail. try { - reportContent = service.generateInventoryReport(topLevelEndpoints, "2023", "2", null, null, null, null, null, null); + reportContent = service.generateInventoryReport(topLevelEndpoints, "2023", "2", null, null, null, null, null, null, null); Assert.fail("Report generated for invalid insurance plan id "); } catch ( CirrasUnderwritingServiceException e ) { // Ok. } + + // Test 6: Omit Report Type for GRAIN: Report generation should fail. + try { + reportContent = service.generateInventoryReport(topLevelEndpoints, "2023", "4", null, null, null, null, null, null, null); + Assert.fail("Report generated for omitted report type"); + } catch ( CirrasUnderwritingServiceException e ) { + // Ok. + } + + // Test 7: Invalid Report Type for GRAIN: Report generation should fail. + try { + reportContent = service.generateInventoryReport(topLevelEndpoints, "2023", "4", null, null, null, null, null, null, "nosuchtype"); + Assert.fail("Report generated for invalid report type"); + } catch ( CirrasUnderwritingServiceException e ) { + // Ok. + } } public void checkInventoryCoverageTotalForage(InventoryCoverageTotalForage expected, InventoryCoverageTotalForage actual) { diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java index b68b229c..940bdc78 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointGrainTest.java @@ -29,9 +29,11 @@ import ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.LegalLandRsrc; import ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.PoliciesSyncEventTypes; import ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.PolicyRsrc; +import ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.ProductRsrc; import ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.UwContractListRsrc; import ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.UwContractRsrc; import ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.VerifiedYieldContractRsrc; +import ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.factory.VerifiedYieldContractRsrcFactory; import ca.bc.gov.mal.cirras.underwriting.api.rest.test.EndpointsTest; import ca.bc.gov.mal.cirras.underwriting.model.v1.DopYieldContractCommodity; import ca.bc.gov.mal.cirras.underwriting.model.v1.DopYieldFieldForage; @@ -96,6 +98,10 @@ public class VerifiedYieldContractEndpointGrainTest extends EndpointsTest { private Integer fieldId = 90000016; private Integer annualFieldDetailId1 = 90000017; private Integer contractedFieldDetailId1 = 90000018; + + private Integer productId1 = 99999999; + private Integer productId2 = 88889999; + private Integer productId3 = 77777777; @Before @@ -114,6 +120,10 @@ public void cleanUp() throws CirrasUnderwritingServiceException, NotFoundDaoExce private void delete() throws NotFoundDaoException, DaoException, CirrasUnderwritingServiceException { + service.deleteProduct(topLevelEndpoints, productId1.toString()); + service.deleteProduct(topLevelEndpoints, productId2.toString()); + service.deleteProduct(topLevelEndpoints, productId3.toString()); + deleteVerifiedYieldContract(policyNumber1); deleteDopYieldContract(policyNumber1); @@ -246,6 +256,11 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting createInventoryContract(policyNumber1, 4); createDopYieldContract(policyNumber1, 4); + //Barley - NON Pedigree - Product + createUpdateProduct(policyId1, productId1, 16, 20, 15.5, barleyNonPediProductionGuarantee, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); + //Barley - Pedigree + createUpdateProduct(policyId1, productId3, 17, 50, 20.5, barleyPedigreeProductionGuarantee, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); + Integer pageNumber = 1; Integer pageRowCount = 20; @@ -290,11 +305,11 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting // Check Rollover //Barley - NON Pedigree - checkVerifiedContractCommodityRollover(newContract.getVerifiedYieldContractCommodities(), 16, false, 23.45); - //Canola - checkVerifiedContractCommodityRollover(newContract.getVerifiedYieldContractCommodities(), 18, true, null); + checkVerifiedContractCommodityRollover(newContract.getVerifiedYieldContractCommodities(), 16, false, barleyNonPediProductionGuarantee, 23.45); + //Canola - Pedigree + checkVerifiedContractCommodityRollover(newContract.getVerifiedYieldContractCommodities(), 18, true, null, null); //Barley - Pedigree - checkVerifiedContractCommodityRollover(newContract.getVerifiedYieldContractCommodities(), 16, true, null); + checkVerifiedContractCommodityRollover(newContract.getVerifiedYieldContractCommodities(), 16, true, barleyPedigreeProductionGuarantee, null); //Check verifiable Commodities and field Assert.assertEquals(1, newContract.getFields().size()); @@ -321,11 +336,14 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting barleyCommodity.setHarvestedAcresOverride(22.0); barleyCommodity.setHarvestedYieldOverride(120.0); + //Create product for Canola - Pedigree + createUpdateProduct(policyId1, productId2, 19, 10, 50.5, canolaPedigreeProductionGuarantee, "Open"); + List expectedCommodities = newContract.getVerifiedYieldContractCommodities(); - + VerifiedYieldContractRsrc createdContract = service.createVerifiedYieldContract(topLevelEndpoints, newContract); Assert.assertNotNull(createdContract); - + Assert.assertEquals(newContract.getContractId(), createdContract.getContractId()); Assert.assertEquals(newContract.getCropYear(), createdContract.getCropYear()); Assert.assertEquals(newContract.getDeclaredYieldContractGuid(), createdContract.getDeclaredYieldContractGuid()); @@ -336,14 +354,27 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting Assert.assertNotNull(createdContract.getVerifiedYieldUpdateUser()); Assert.assertNotNull(createdContract.getVerifiedYieldUpdateTimestamp()); + //Even though there is a product for canola now, there is no warning because purchase is not in status FINAL + Assert.assertEquals(0, createdContract.getProductWarningMessages().size()); + // Check Contract Commodities //Barley - NON Pedigree - checkVerifiedContractCommodityTotals(expectedCommodities, createdContract.getVerifiedYieldContractCommodities(), 16, false, 23.45); - //Canola - checkVerifiedContractCommodityTotals(expectedCommodities, createdContract.getVerifiedYieldContractCommodities(), 18, true, null); + checkVerifiedContractCommodityTotals(expectedCommodities, createdContract.getVerifiedYieldContractCommodities(), 16, false, barleyNonPediProductionGuarantee, 23.45); + //Canola - Pedigree + checkVerifiedContractCommodityTotals(expectedCommodities, createdContract.getVerifiedYieldContractCommodities(), 18, true, null, null); //Barley - Pedigree - checkVerifiedContractCommodityTotals(expectedCommodities, createdContract.getVerifiedYieldContractCommodities(), 16, true, null); + checkVerifiedContractCommodityTotals(expectedCommodities, createdContract.getVerifiedYieldContractCommodities(), 16, true, barleyPedigreeProductionGuarantee, null); + //Delete Barley non Pedigree Product - Expect warning + service.deleteProduct(topLevelEndpoints, productId1.toString()); + //Update Barley Pedigree Product Guarantee - Expect warning + Double barleyPedProdGuaranteeNew = barleyPedigreeProductionGuarantee + 20; + createUpdateProduct(policyId1, productId3, 17, 50, 20.5, barleyPedProdGuaranteeNew, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); + + //Get contract again to prevent precondition fails + createdContract = getVerifiedYieldContract(policyNumber1); + Assert.assertNotNull(createdContract); + //Update verified contract ****************************************************************************** //Remove override values for barley non pedigree barleyCommodity = getVerifiedYieldContractCommodity(16, false, createdContract.getVerifiedYieldContractCommodities()); @@ -351,6 +382,9 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting barleyCommodity.setHarvestedAcresOverride(null); barleyCommodity.setHarvestedYieldOverride(null); + //DON'T update product values + createdContract.setUpdateProductValuesInd(false); + expectedCommodities = createdContract.getVerifiedYieldContractCommodities(); VerifiedYieldContractRsrc updatedContract = service.updateVerifiedYieldContract(createdContract); @@ -365,17 +399,67 @@ public void testInsertUpdateDeleteGrainVerifiedYield() throws CirrasUnderwriting Assert.assertEquals(createdContract.getVerifiedYieldContractGuid(), updatedContract.getVerifiedYieldContractGuid()); Assert.assertEquals(createdContract.getVerifiedYieldUpdateUser(), updatedContract.getVerifiedYieldUpdateUser()); Assert.assertNotNull(updatedContract.getVerifiedYieldUpdateTimestamp()); + + //2 warnings expected + Assert.assertEquals(2, updatedContract.getProductWarningMessages().size()); + + // Check Contract Commodities + //Barley - NON Pedigree + checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 16, false, barleyNonPediProductionGuarantee, 23.45); + //Canola - Pedigree + checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 18, true, null, null); + //Barley - Pedigree + checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 16, true, barleyPedigreeProductionGuarantee, null); + + //UPDATE product values + updatedContract.setUpdateProductValuesInd(true); + + updatedContract = service.updateVerifiedYieldContract(updatedContract); + Assert.assertNotNull(updatedContract); + + //0 warnings expected + Assert.assertEquals(0, updatedContract.getProductWarningMessages().size()); + + // Check Contract Commodities + //Barley - NON Pedigree + checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 16, false, null, 23.45); + //Canola - Pedigree + checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 18, true, null, null); + //Barley - Pedigree + checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 16, true, barleyPedProdGuaranteeNew, null); + + //Update Barley Pedigree Product Guarantee to NULL - Expect warning + createUpdateProduct(policyId1, productId3, 17, 50, 20.5, null, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); + //Update Canola Pedigree to status final + createUpdateProduct(policyId1, productId2, 19, 10, 50.5, canolaPedigreeProductionGuarantee, VerifiedYieldContractRsrcFactory.PRODUCT_STATUS_FINAL); + + //Get contract + VerifiedYieldContractRsrc vyContract = getVerifiedYieldContract(policyNumber1); + Assert.assertNotNull(vyContract); + + //2 warnings expected + Assert.assertEquals(2, vyContract.getProductWarningMessages().size()); + + //UPDATE product values + vyContract.setUpdateProductValuesInd(true); + + vyContract = service.updateVerifiedYieldContract(vyContract); + Assert.assertNotNull(vyContract); + + //0 warnings expected + Assert.assertEquals(0, updatedContract.getProductWarningMessages().size()); // Check Contract Commodities //Barley - NON Pedigree - checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 16, false, 23.45); - //Canola - checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 18, true, null); + checkVerifiedContractCommodityTotals(expectedCommodities, vyContract.getVerifiedYieldContractCommodities(), 16, false, null, 23.45); + //Canola - Pedigree + checkVerifiedContractCommodityTotals(expectedCommodities, vyContract.getVerifiedYieldContractCommodities(), 18, true, canolaPedigreeProductionGuarantee, null); //Barley - Pedigree - checkVerifiedContractCommodityTotals(expectedCommodities, updatedContract.getVerifiedYieldContractCommodities(), 16, true, null); + checkVerifiedContractCommodityTotals(expectedCommodities, vyContract.getVerifiedYieldContractCommodities(), 16, true, null, null); + //Delete verified contract ****************************************************************************** - service.deleteVerifiedYieldContract(updatedContract); + service.deleteVerifiedYieldContract(vyContract); searchResults = service.getUwContractList( topLevelEndpoints, @@ -406,6 +490,7 @@ private void checkVerifiedContractCommodityTotals( List actualCommodities, Integer cropCommodityId, Boolean isPedigreeInd, + Double productionGuarantee, Double insuredAcres) { VerifiedYieldContractCommodity expectedCommodity = getVerifiedYieldContractCommodity(cropCommodityId, isPedigreeInd, expectedCommodities); @@ -436,7 +521,7 @@ private void checkVerifiedContractCommodityTotals( Assert.assertEquals(expectedCommodity.getHarvestedAcresOverride(), actualCommodity.getHarvestedAcresOverride()); Assert.assertEquals(expectedCommodity.getHarvestedYieldOverride(), actualCommodity.getHarvestedYieldOverride()); Assert.assertEquals(expectedCommodity.getIsPedigreeInd(), actualCommodity.getIsPedigreeInd()); - Assert.assertEquals(null, actualCommodity.getProductionGuarantee()); //TODO + Assert.assertEquals(productionGuarantee, actualCommodity.getProductionGuarantee()); Assert.assertEquals(expectedCommodity.getSoldYieldDefaultUnit(), actualCommodity.getSoldYieldDefaultUnit()); Assert.assertEquals(expectedCommodity.getStoredYieldDefaultUnit(), actualCommodity.getStoredYieldDefaultUnit()); Assert.assertEquals(insuredAcres, actualCommodity.getTotalInsuredAcres()); @@ -449,6 +534,7 @@ private void checkVerifiedContractCommodityRollover( List verifiedCommodities, Integer cropCommodityId, Boolean isPedigreeInd, + Double productionGuarantee, Double insuredAcres) { DopYieldContractCommodity dopCommodity = getDopYieldContractCommodity(cropCommodityId, isPedigreeInd, dopYieldContractCommodityList); @@ -481,7 +567,7 @@ private void checkVerifiedContractCommodityRollover( Assert.assertEquals(null, verifiedCommodity.getHarvestedAcresOverride()); Assert.assertEquals(null, verifiedCommodity.getHarvestedYieldOverride()); Assert.assertEquals(dopCommodity.getIsPedigreeInd(), verifiedCommodity.getIsPedigreeInd()); - Assert.assertEquals(null, verifiedCommodity.getProductionGuarantee()); //TODO + Assert.assertEquals(productionGuarantee, verifiedCommodity.getProductionGuarantee()); Assert.assertEquals(dopCommodity.getSoldYieldDefaultUnit(), verifiedCommodity.getSoldYieldDefaultUnit()); Assert.assertEquals(dopCommodity.getStoredYieldDefaultUnit(), verifiedCommodity.getStoredYieldDefaultUnit()); Assert.assertEquals(insuredAcres, verifiedCommodity.getTotalInsuredAcres()); @@ -504,6 +590,35 @@ private DopYieldContractCommodity getDopYieldContractCommodity(Integer cropCommo return dycc; } + private VerifiedYieldContractRsrc getVerifiedYieldContract(String policyNumber) throws NotFoundDaoException, DaoException, CirrasUnderwritingServiceException { + + Integer pageNumber = 1; + Integer pageRowCount = 20; + + UwContractListRsrc searchResults = service.getUwContractList( + topLevelEndpoints, + null, + null, + null, + null, + policyNumber, + null, + null, + null, + null, + pageNumber, pageRowCount); + + if ( searchResults.getCollection() != null && searchResults.getCollection().size() == 1 ) { + UwContractRsrc referrer = searchResults.getCollection().get(0); + + if ( referrer.getVerifiedYieldContractGuid() != null ) { + return service.getVerifiedYieldContract(referrer); + } + } + + return null; + } + private VerifiedYieldContractCommodity getVerifiedYieldContractCommodity(Integer cropCommodityId, Boolean isPedigree, List vyccList) { VerifiedYieldContractCommodity vycc = null; @@ -672,6 +787,47 @@ private void createGrower(Integer growerId, Integer growerNumber, String growerN } + private Double barleyNonPediProductionGuarantee = 222.5; + private Double barleyPedigreeProductionGuarantee = 15.1; + private Double canolaPedigreeProductionGuarantee = 77.0; + + private void createUpdateProduct( + Integer policyId, + Integer productId, + Integer cropCommodityId, + Integer deductibleLevel, + Double probableYield, + Double productionGuarantee, + String productStatusCode + ) throws CirrasUnderwritingServiceException, ValidationException { + + //Date and Time without millisecond + Calendar cal = Calendar.getInstance(); + cal.set(Calendar.MILLISECOND, 0); //Set milliseconds to 0 because they are not set in the database + Date transactionDate = cal.getTime(); + + Date createTransactionDate = addSeconds(transactionDate, -1); + + //CREATE Product + ProductRsrc product = new ProductRsrc(); + + product.setCommodityCoverageCode("CQG"); + product.setCropCommodityId(cropCommodityId); + product.setDeductibleLevel(deductibleLevel); + product.setInsuredByMeasType("ACRES"); + product.setPolicyId(policyId); + product.setProbableYield(probableYield); + product.setProductId(productId); + product.setProductionGuarantee(productionGuarantee); + product.setProductStatusCode(productStatusCode); + + product.setDataSyncTransDate(createTransactionDate); + product.setTransactionType(PoliciesSyncEventTypes.ProductCreated); + + service.synchronizeProduct(product); + + } + private void createInventoryContract(String policyNumber, Integer insurancePlanId) throws ValidationException, CirrasUnderwritingServiceException { boolean addedSeededGrain = false; diff --git a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointTest.java b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointTest.java index b03aa1d7..0dee2074 100644 --- a/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointTest.java +++ b/cirras-underwriting-api/cirras-underwriting-api-rest-endpoints/src/test/java/ca/bc/gov/mal/cirras/underwriting/api/rest/v1/endpoints/VerifiedYieldContractEndpointTest.java @@ -20,7 +20,6 @@ import ca.bc.gov.mal.cirras.underwriting.api.rest.v1.resource.VerifiedYieldContractRsrc; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldAmendment; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContractCommodity; -import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.ContractedFieldDetailDto; import ca.bc.gov.mal.cirras.underwriting.api.rest.test.EndpointsTest; import ca.bc.gov.nrs.wfone.common.persistence.dao.DaoException; import ca.bc.gov.nrs.wfone.common.persistence.dao.NotFoundDaoException; diff --git a/cirras-underwriting-api/cirras-underwriting-model/src/main/java/ca/bc/gov/mal/cirras/underwriting/model/v1/VerifiedYieldContract.java b/cirras-underwriting-api/cirras-underwriting-model/src/main/java/ca/bc/gov/mal/cirras/underwriting/model/v1/VerifiedYieldContract.java index 7f5f1933..41fac5c6 100644 --- a/cirras-underwriting-api/cirras-underwriting-model/src/main/java/ca/bc/gov/mal/cirras/underwriting/model/v1/VerifiedYieldContract.java +++ b/cirras-underwriting-api/cirras-underwriting-model/src/main/java/ca/bc/gov/mal/cirras/underwriting/model/v1/VerifiedYieldContract.java @@ -4,7 +4,9 @@ import java.util.Date; import java.util.List; -public interface VerifiedYieldContract extends Serializable { +import ca.bc.gov.nrs.wfone.common.model.Message; + +public interface VerifiedYieldContract extends Serializable { public String getVerifiedYieldContractGuid(); public void setVerifiedYieldContractGuid(String verifiedYieldContractGuid); @@ -32,6 +34,9 @@ public interface VerifiedYieldContract extends Serializab public Integer getGrowerContractYearId(); public void setGrowerContractYearId(Integer growerContractYearId); + + public Boolean getUpdateProductValuesInd(); + public void setUpdateProductValuesInd(Boolean updateProductValuesInd); public List getFields(); public void setFields(List fields); @@ -41,4 +46,8 @@ public interface VerifiedYieldContract extends Serializab public List getVerifiedYieldAmendments(); public void setVerifiedYieldAmendments(List verifiedYieldAmendments); + + public List getProductWarningMessages(); + public void setProductWarningMessages(List productWarningMessages); + } diff --git a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDao.java b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDao.java index d6c15a67..c2f4738d 100644 --- a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDao.java +++ b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDao.java @@ -2,6 +2,7 @@ import java.io.Serializable; +import java.util.List; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.ProductDto; import ca.bc.gov.nrs.wfone.common.persistence.dao.DaoException; @@ -13,6 +14,11 @@ public interface ProductDao extends Serializable { ProductDto fetch( Integer productId ) throws DaoException; + + public List getForPolicy( + Integer contractId, + Integer cropYear + ) throws DaoException; void insert( ProductDto dto, diff --git a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/ProductDaoImpl.java b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/ProductDaoImpl.java index 29bc19c5..64d8051e 100644 --- a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/ProductDaoImpl.java +++ b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/ProductDaoImpl.java @@ -1,6 +1,7 @@ package ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.mybatis; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.slf4j.Logger; @@ -48,6 +49,28 @@ public ProductDto fetch(Integer productId) throws DaoException { return result; } + @Override + public List getForPolicy(Integer contractId, Integer cropYear) throws DaoException { + + logger.debug(" dtos = null; + + try { + Map parameters = new HashMap(); + + parameters.put("contractId", contractId); + parameters.put("cropYear", cropYear); + + dtos = this.mapper.getForPolicy(parameters); + + } catch (RuntimeException e) { + handleException(e); + } + + logger.debug(">getForPolicy " + dtos); + return dtos; + } @Override public void insert(ProductDto dto, String userId) throws DaoException { diff --git a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.java b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.java index dd62151e..1641d3c8 100644 --- a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.java +++ b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.java @@ -1,5 +1,6 @@ package ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.mybatis.mapper; +import java.util.List; import java.util.Map; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.ProductDto; @@ -8,6 +9,8 @@ public interface ProductMapper { ProductDto fetch(Map parameters); + List getForPolicy(Map parameters); + int insert(Map parameters); int update(Map parameters); diff --git a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dto/ProductDto.java b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dto/ProductDto.java index 62d0f787..60ae3da9 100644 --- a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dto/ProductDto.java +++ b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dto/ProductDto.java @@ -29,6 +29,8 @@ public class ProductDto extends BaseDto { private String insuredByMeasType; private Date dataSyncTransDate; + private Integer nonPedigreeCropCommodityId; + private Boolean isPedigreeProduct; private String createUser; private Date createDate; @@ -52,6 +54,8 @@ public ProductDto(ProductDto dto) { this.insuredByMeasType = dto.insuredByMeasType; this.dataSyncTransDate = dto.dataSyncTransDate; + this.nonPedigreeCropCommodityId = dto.nonPedigreeCropCommodityId; + this.isPedigreeProduct = dto.isPedigreeProduct; this.createUser = dto.createUser; this.createDate = dto.createDate; @@ -163,7 +167,23 @@ public String getInsuredByMeasType() { public void setInsuredByMeasType(String insuredByMeasType) { this.insuredByMeasType = insuredByMeasType; } + + public Integer getNonPedigreeCropCommodityId() { + return nonPedigreeCropCommodityId; + } + + public void setNonPedigreeCropCommodityId(Integer nonPedigreeCropCommodityId) { + this.nonPedigreeCropCommodityId = nonPedigreeCropCommodityId; + } + + public Boolean getIsPedigreeProduct() { + return isPedigreeProduct; + } + public void setIsPedigreeProduct(Boolean isPedigreeProduct) { + this.isPedigreeProduct = isPedigreeProduct; + } + public Date getDataSyncTransDate() { return dataSyncTransDate; } @@ -198,5 +218,5 @@ public Date getUpdateDate() { public void setUpdateDate(Date updateDate) { this.updateDate = updateDate; } - + } diff --git a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/resources/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.xml b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/resources/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.xml index 726e11cc..a1553eb9 100644 --- a/cirras-underwriting-api/cirras-underwriting-persistence/src/main/resources/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.xml +++ b/cirras-underwriting-api/cirras-underwriting-persistence/src/main/resources/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/mybatis/mapper/ProductMapper.xml @@ -15,9 +15,10 @@ - - + + + @@ -49,6 +50,23 @@ WHERE t.product_id = #{productId} + + INSERT INTO product( diff --git a/cirras-underwriting-api/cirras-underwriting-persistence/src/test/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDaoTest.java b/cirras-underwriting-api/cirras-underwriting-persistence/src/test/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDaoTest.java index cc76033b..3ae8a69e 100644 --- a/cirras-underwriting-api/cirras-underwriting-persistence/src/test/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDaoTest.java +++ b/cirras-underwriting-api/cirras-underwriting-persistence/src/test/java/ca/bc/gov/mal/cirras/underwriting/persistence/v1/dao/ProductDaoTest.java @@ -2,6 +2,7 @@ import java.util.Calendar; import java.util.Date; +import java.util.List; import org.junit.After; import org.junit.Assert; @@ -28,6 +29,7 @@ public class ProductDaoTest { private PersistenceSpringConfig persistenceSpringConfig; private Integer productId = 99999999; + private Integer productId2 = 79999999; private Integer policyId1 = 90000001; private Integer contractId1 = 90000002; @@ -51,6 +53,7 @@ public void cleanUp() throws NotFoundDaoException, DaoException{ private void delete() throws NotFoundDaoException, DaoException { deleteProduct(productId); + deleteProduct(productId2); deletePolicy(policyId1); deleteGrower(growerId1); } @@ -191,16 +194,7 @@ public void testInsertUpdateDeleteProduct() throws Exception { //FETCH ProductDto fetchedDto = dao.fetch(productId); - Assert.assertEquals("CommodityCoverageCode", newDto.getCommodityCoverageCode(), fetchedDto.getCommodityCoverageCode()); - Assert.assertEquals("CropCommodityId", newDto.getCropCommodityId(), fetchedDto.getCropCommodityId()); - Assert.assertEquals("DeductibleLevel", newDto.getDeductibleLevel(), fetchedDto.getDeductibleLevel()); - Assert.assertEquals("InsuredByMeasType", newDto.getInsuredByMeasType(), fetchedDto.getInsuredByMeasType()); - Assert.assertEquals("PolicyId", newDto.getPolicyId(), fetchedDto.getPolicyId()); - Assert.assertEquals("ProbableYield", newDto.getProbableYield(), fetchedDto.getProbableYield()); - Assert.assertEquals("ProductId", newDto.getProductId(), fetchedDto.getProductId()); - Assert.assertEquals("ProductionGuarantee", newDto.getProductionGuarantee(), fetchedDto.getProductionGuarantee()); - Assert.assertEquals("ProductStatusCode", newDto.getProductStatusCode(), fetchedDto.getProductStatusCode()); - Assert.assertEquals("DataSyncTransDate", newDto.getDataSyncTransDate(), fetchedDto.getDataSyncTransDate()); + checkProduct(newDto, fetchedDto); //UPDATE dataSyncTransDate = addSeconds(dateTime, -60); @@ -220,16 +214,7 @@ public void testInsertUpdateDeleteProduct() throws Exception { //FETCH ProductDto updatedDto = dao.fetch(productId); - Assert.assertEquals("CommodityCoverageCode", fetchedDto.getCommodityCoverageCode(), updatedDto.getCommodityCoverageCode()); - Assert.assertEquals("CropCommodityId", fetchedDto.getCropCommodityId(), updatedDto.getCropCommodityId()); - Assert.assertEquals("DeductibleLevel", fetchedDto.getDeductibleLevel(), updatedDto.getDeductibleLevel()); - Assert.assertEquals("InsuredByMeasType", fetchedDto.getInsuredByMeasType(), updatedDto.getInsuredByMeasType()); - Assert.assertEquals("PolicyId", fetchedDto.getPolicyId(), updatedDto.getPolicyId()); - Assert.assertEquals("ProbableYield", fetchedDto.getProbableYield(), updatedDto.getProbableYield()); - Assert.assertEquals("ProductId", fetchedDto.getProductId(), updatedDto.getProductId()); - Assert.assertEquals("ProductionGuarantee", fetchedDto.getProductionGuarantee(), updatedDto.getProductionGuarantee()); - Assert.assertEquals("ProductStatusCode", fetchedDto.getProductStatusCode(), updatedDto.getProductStatusCode()); - Assert.assertEquals("DataSyncTransDate", fetchedDto.getDataSyncTransDate(), updatedDto.getDataSyncTransDate()); + checkProduct(fetchedDto, updatedDto); //Expect NO update becaus the transaction date is before the latest update userId = "JUNIT_TEST_NO_UPDATE"; @@ -244,6 +229,46 @@ public void testInsertUpdateDeleteProduct() throws Exception { //DataSyncTransDate is still the same (no update happened) Assert.assertTrue("DataSyncTransDate 3", notUpdatedDto.getDataSyncTransDate().compareTo(dataSyncTransDate) == 0); + + //Test get for policy + + //Add second product + dao = persistenceSpringConfig.productDao(); + + newDto = new ProductDto(); + + newDto.setCommodityCoverageCode("CQG"); + newDto.setCropCommodityId(25); //Pedigree product + newDto.setDeductibleLevel(20); + newDto.setInsuredByMeasType("ACRES"); + newDto.setPolicyId(policyId1); + newDto.setProbableYield(22.2); + newDto.setProductId(productId2); + newDto.setProductionGuarantee(99.0); + newDto.setProductStatusCode("FINAL"); + newDto.setNonPedigreeCropCommodityId(24); + newDto.setIsPedigreeProduct(true); + + newDto.setDataSyncTransDate(dataSyncTransDate); + + //INSERT + dao.insert(newDto, userId); + + //Set expected values for first product + notUpdatedDto.setNonPedigreeCropCommodityId(notUpdatedDto.getCropCommodityId()); + notUpdatedDto.setIsPedigreeProduct(false); + + List dtos = dao.getForPolicy(contractId1, cropYear1); + Assert.assertEquals(2, dtos.size()); + + for(ProductDto dto : dtos) { + if(dto.getCropCommodityId().equals(newDto.getCropCommodityId())) { + checkProduct(newDto, dto); + } else { + checkProduct(notUpdatedDto, dto); + } + } + //DELETE dao.delete(productId); @@ -251,6 +276,23 @@ public void testInsertUpdateDeleteProduct() throws Exception { ProductDto deletedDto = dao.fetch(productId); Assert.assertNull(deletedDto); } + + private void checkProduct(ProductDto expected, ProductDto actual) { + Assert.assertEquals("CommodityCoverageCode", expected.getCommodityCoverageCode(), actual.getCommodityCoverageCode()); + Assert.assertEquals("CropCommodityId", expected.getCropCommodityId(), actual.getCropCommodityId()); + Assert.assertEquals("DeductibleLevel", expected.getDeductibleLevel(), actual.getDeductibleLevel()); + Assert.assertEquals("InsuredByMeasType", expected.getInsuredByMeasType(), actual.getInsuredByMeasType()); + Assert.assertEquals("PolicyId", expected.getPolicyId(), actual.getPolicyId()); + Assert.assertEquals("ProbableYield", expected.getProbableYield(), actual.getProbableYield()); + Assert.assertEquals("ProductId", expected.getProductId(), actual.getProductId()); + Assert.assertEquals("ProductionGuarantee", expected.getProductionGuarantee(), actual.getProductionGuarantee()); + Assert.assertEquals("ProductStatusCode", expected.getProductStatusCode(), actual.getProductStatusCode()); + Assert.assertEquals("DataSyncTransDate", expected.getDataSyncTransDate(), actual.getDataSyncTransDate()); + + Assert.assertEquals("NonPedigreeCropCommodityId", expected.getNonPedigreeCropCommodityId(), actual.getNonPedigreeCropCommodityId()); + Assert.assertEquals("IsPedigreeProduct", expected.getIsPedigreeProduct(), actual.getIsPedigreeProduct()); + + } private static Date addSeconds(Date date, Integer seconds) { Calendar cal = Calendar.getInstance(); diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/CirrasInventoryService.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/CirrasInventoryService.java index 4a950bef..ae835a1c 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/CirrasInventoryService.java +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/CirrasInventoryService.java @@ -165,6 +165,7 @@ byte[] generateInvReport( String growerInfo, String sortColumn, String policyIds, + String reportType, FactoryContext factoryContext, WebAdeAuthentication authentication ) diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/CirrasVerifiedYieldService.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/CirrasVerifiedYieldService.java index f33f2320..99fb796d 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/CirrasVerifiedYieldService.java +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/CirrasVerifiedYieldService.java @@ -4,6 +4,7 @@ import ca.bc.gov.mal.cirras.underwriting.model.v1.AnnualField; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContract; +import ca.bc.gov.nrs.wfone.common.model.Message; import ca.bc.gov.nrs.wfone.common.service.api.ConflictException; import ca.bc.gov.nrs.wfone.common.service.api.ForbiddenException; import ca.bc.gov.nrs.wfone.common.service.api.NotFoundException; @@ -15,7 +16,7 @@ public interface CirrasVerifiedYieldService { @Transactional(readOnly = true, rollbackFor = Exception.class) - VerifiedYieldContract rolloverVerifiedYieldContract( + VerifiedYieldContract rolloverVerifiedYieldContract( Integer policyId, FactoryContext factoryContext, WebAdeAuthentication authentication @@ -23,7 +24,7 @@ VerifiedYieldContract rolloverVerifiedYieldContract( throws ServiceException, NotFoundException; @Transactional(readOnly = true, rollbackFor = Exception.class) - VerifiedYieldContract getVerifiedYieldContract( + VerifiedYieldContract getVerifiedYieldContract( String verifiedYieldContractGuid, FactoryContext factoryContext, WebAdeAuthentication authentication @@ -31,18 +32,18 @@ VerifiedYieldContract getVerifiedYieldContract( throws ServiceException, NotFoundException; @Transactional(readOnly = false, rollbackFor = Exception.class) - VerifiedYieldContract createVerifiedYieldContract( - VerifiedYieldContract verifiedYieldContract, + VerifiedYieldContract createVerifiedYieldContract( + VerifiedYieldContract verifiedYieldContract, FactoryContext factoryContext, WebAdeAuthentication authentication ) throws ServiceException, NotFoundException, ValidationFailureException; @Transactional(readOnly = false, rollbackFor = Exception.class) - VerifiedYieldContract updateVerifiedYieldContract( + VerifiedYieldContract updateVerifiedYieldContract( String verifiedYieldContractGuid, String optimisticLock, - VerifiedYieldContract verifiedYieldContract, + VerifiedYieldContract verifiedYieldContract, FactoryContext factoryContext, WebAdeAuthentication authentication ) diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasInventoryServiceImpl.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasInventoryServiceImpl.java index 9fc2c5d7..a1ae181b 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasInventoryServiceImpl.java +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasInventoryServiceImpl.java @@ -100,6 +100,7 @@ import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.InventoryServiceEnums; import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.InventoryServiceEnums.InsurancePlans; import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.InventoryServiceEnums.InventoryCalculationType; +import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.InventoryServiceEnums.InventoryReportType; import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.LandUpdateTypes; import ca.bc.gov.mal.cirras.underwriting.service.api.v1.util.OutOfSync; import ca.bc.gov.mal.cirras.underwriting.service.api.v1.validation.ModelValidator; @@ -1242,7 +1243,7 @@ private InventoryContractDto getInventoryContractDtoForPrintout(String inventory @Override public byte[] generateInvReport(Integer cropYear, Integer insurancePlanId, Integer officeId, - String policyStatusCode, String policyNumber, String growerInfo, String sortColumn, String policyIds, + String policyStatusCode, String policyNumber, String growerInfo, String sortColumn, String policyIds, String reportType, FactoryContext factoryContext, WebAdeAuthentication authentication) throws ServiceException, NotFoundException { @@ -1285,7 +1286,16 @@ public byte[] generateInvReport(Integer cropYear, Integer insurancePlanId, Integ // Pick the jasper report to run based on plan. if ( InsurancePlans.GRAIN.getInsurancePlanId().equals(insurancePlanId) ) { - result = jasperReportService.generateInvGrainReport(queryParams); + + if ( InventoryReportType.unseeded.name().equals(reportType) ) { + result = jasperReportService.generateUnseededGrainReport(queryParams); + + } else if ( InventoryReportType.seeded.name().equals(reportType) ) { + result = jasperReportService.generateSeededGrainReport(queryParams); + + } else { + throw new ServiceException("Report Type for Grain Inventory must be unseeded or seeded"); + } } else if ( InsurancePlans.FORAGE.getInsurancePlanId().equals(insurancePlanId) ) { result = jasperReportService.generateInvForageReport(queryParams); diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasVerifiedYieldServiceImpl.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasVerifiedYieldServiceImpl.java index c0e760d5..1fadea9f 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasVerifiedYieldServiceImpl.java +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/impl/CirrasVerifiedYieldServiceImpl.java @@ -16,6 +16,7 @@ import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.InventoryFieldDao; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.InventorySeededGrainDao; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.PolicyDao; +import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.ProductDao; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.VerifiedYieldAmendmentDao; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.VerifiedYieldContractCommodityDao; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dao.VerifiedYieldContractDao; @@ -25,6 +26,7 @@ import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.InventoryFieldDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.InventorySeededGrainDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.PolicyDto; +import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.ProductDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldAmendmentDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldContractCommodityDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldContractDto; @@ -67,6 +69,7 @@ public class CirrasVerifiedYieldServiceImpl implements CirrasVerifiedYieldServic private VerifiedYieldContractDao verifiedYieldContractDao; private VerifiedYieldContractCommodityDao verifiedYieldContractCommodityDao; private VerifiedYieldAmendmentDao verifiedYieldAmendmentDao; + private ProductDao productDao; public void setApplicationProperties(Properties applicationProperties) { this.applicationProperties = applicationProperties; @@ -116,14 +119,19 @@ public void setVerifiedYieldAmendmentDao(VerifiedYieldAmendmentDao verifiedYield this.verifiedYieldAmendmentDao = verifiedYieldAmendmentDao; } + public void setProductDao(ProductDao productDao) { + this.productDao = productDao; + } + + @Override - public VerifiedYieldContract rolloverVerifiedYieldContract(Integer policyId, + public VerifiedYieldContract rolloverVerifiedYieldContract(Integer policyId, FactoryContext factoryContext, WebAdeAuthentication authentication) throws ServiceException, NotFoundException { logger.debug(" result = null; + VerifiedYieldContract result = null; try { @@ -139,10 +147,11 @@ public VerifiedYieldContract rolloverVerifiedYieldContrac throw new NotFoundException("Did not find the dop: " + policyDto.getDeclaredYieldContractGuid()); } + List productDtos = loadProducts(dycDto.getContractId(), dycDto.getCropYear()); loadDopYieldContractCommodities(dycDto); loadFields(dycDto); - result = verifiedYieldContractFactory.getDefaultVerifiedYieldContract(policyDto, dycDto, factoryContext, authentication); + result = verifiedYieldContractFactory.getDefaultVerifiedYieldContract(policyDto, dycDto, productDtos, factoryContext, authentication); calculateVerifiedYieldContractCommodities(result); @@ -164,7 +173,7 @@ private void loadDopYieldContractCommodities(DeclaredYieldContractDto dto) throw } } - private void calculateVerifiedYieldContractCommodities(VerifiedYieldContract verifiedYieldContract) { + private void calculateVerifiedYieldContractCommodities(VerifiedYieldContract verifiedYieldContract) { if ( verifiedYieldContract.getVerifiedYieldContractCommodities() != null && !verifiedYieldContract.getVerifiedYieldContractCommodities().isEmpty() ) { for ( VerifiedYieldContractCommodity vycc : verifiedYieldContract.getVerifiedYieldContractCommodities() ) { @@ -239,13 +248,13 @@ private void loadSeededGrains(InventoryFieldDto ifDto) throws DaoException { } @Override - public VerifiedYieldContract getVerifiedYieldContract(String verifiedYieldContractGuid, + public VerifiedYieldContract getVerifiedYieldContract(String verifiedYieldContractGuid, FactoryContext factoryContext, WebAdeAuthentication authentication) throws ServiceException, NotFoundException { logger.debug(" result = null; + VerifiedYieldContract result = null; try { VerifiedYieldContractDto dto = verifiedYieldContractDao.fetch(verifiedYieldContractGuid); @@ -264,19 +273,23 @@ public VerifiedYieldContract getVerifiedYieldContract(Str return result; } - private VerifiedYieldContract loadVerifiedYieldContract( + private VerifiedYieldContract loadVerifiedYieldContract( VerifiedYieldContractDto dto, FactoryContext factoryContext, WebAdeAuthentication authentication) throws DaoException { + List productDtos = loadProducts(dto.getContractId(), dto.getCropYear()); loadVerifiedYieldContractCommodities(dto); loadVerifiedYieldAmendments(dto); loadFields(dto); - return verifiedYieldContractFactory.getVerifiedYieldContract(dto, factoryContext, authentication); + return verifiedYieldContractFactory.getVerifiedYieldContract(dto, productDtos, factoryContext, authentication); + } + + private List loadProducts(Integer contractId, Integer cropYear) throws DaoException { + return productDao.getForPolicy(contractId, cropYear); } - private void loadVerifiedYieldContractCommodities(VerifiedYieldContractDto dto) throws DaoException { List verifiedCommodities = verifiedYieldContractCommodityDao.selectForVerifiedYieldContract(dto.getVerifiedYieldContractGuid()); dto.setVerifiedYieldContractCommodities(verifiedCommodities); @@ -288,14 +301,14 @@ private void loadVerifiedYieldAmendments(VerifiedYieldContractDto dto) throws Da } @Override - public VerifiedYieldContract createVerifiedYieldContract( - VerifiedYieldContract verifiedYieldContract, FactoryContext factoryContext, + public VerifiedYieldContract createVerifiedYieldContract( + VerifiedYieldContract verifiedYieldContract, FactoryContext factoryContext, WebAdeAuthentication authentication) throws ServiceException, NotFoundException, ValidationFailureException { logger.debug(" result = null; + VerifiedYieldContract result = null; String userId = getUserId(authentication); try { @@ -317,7 +330,7 @@ public VerifiedYieldContract createVerifiedYieldContract( List verifiedContractCommodities = verifiedYieldContract.getVerifiedYieldContractCommodities(); if (verifiedContractCommodities != null && !verifiedContractCommodities.isEmpty()) { for (VerifiedYieldContractCommodity verifiedContractCommodity : verifiedContractCommodities) { - updateVerifiedYieldContractCommodity(verifiedYieldContractGuid, verifiedContractCommodity, userId); + updateVerifiedYieldContractCommodity(verifiedYieldContractGuid, verifiedContractCommodity, null, false, userId); } } } else if ( InsurancePlans.FORAGE.getInsurancePlanId().equals(verifiedYieldContract.getInsurancePlanId()) ) { @@ -336,7 +349,7 @@ public VerifiedYieldContract createVerifiedYieldContract( return result; } - private String insertVerifiedYieldContract(VerifiedYieldContract verifiedYieldContract, String userId) + private String insertVerifiedYieldContract(VerifiedYieldContract verifiedYieldContract, String userId) throws DaoException { VerifiedYieldContractDto dto = new VerifiedYieldContractDto(); @@ -350,6 +363,8 @@ private String insertVerifiedYieldContract(VerifiedYieldContract productDtos, + Boolean updateProductValues, String userId) throws DaoException { logger.debug(" updateVerifiedYieldContract( + public VerifiedYieldContract updateVerifiedYieldContract( String verifiedYieldContractGuid, String optimisticLock, - VerifiedYieldContract verifiedYieldContract, + VerifiedYieldContract verifiedYieldContract, FactoryContext factoryContext, WebAdeAuthentication authentication) throws ServiceException, NotFoundException, ForbiddenException, ConflictException, ValidationFailureException { logger.debug(" result = null; + VerifiedYieldContract result = null; String userId = getUserId(authentication); try { @@ -416,6 +431,12 @@ public VerifiedYieldContract updateVerifiedYieldContract( if ( InsurancePlans.GRAIN.getInsurancePlanId().equals(verifiedYieldContract.getInsurancePlanId()) ) { + List productDtos = null; + //Get products if the user wants to update the product data + if(Boolean.TRUE.equals(verifiedYieldContract.getUpdateProductValuesInd())) { + productDtos = loadProducts(verifiedYieldContract.getContractId(), verifiedYieldContract.getCropYear()); + } + //Calculate harvested yield and yield per acre calculateVerifiedYieldContractCommodities(verifiedYieldContract); @@ -423,7 +444,7 @@ public VerifiedYieldContract updateVerifiedYieldContract( List verifiedContractCommodities = verifiedYieldContract.getVerifiedYieldContractCommodities(); if (verifiedContractCommodities != null && !verifiedContractCommodities.isEmpty()) { for (VerifiedYieldContractCommodity verifiedContractCommodity : verifiedContractCommodities) { - updateVerifiedYieldContractCommodity(verifiedYieldContractGuid, verifiedContractCommodity, userId); + updateVerifiedYieldContractCommodity(verifiedYieldContractGuid, verifiedContractCommodity, productDtos, verifiedYieldContract.getUpdateProductValuesInd(), userId); } } @@ -443,7 +464,7 @@ public VerifiedYieldContract updateVerifiedYieldContract( return result; } - private void updateVerifiedYieldContract(VerifiedYieldContract verifiedYieldContract, String userId) + private void updateVerifiedYieldContract(VerifiedYieldContract verifiedYieldContract, String userId) throws DaoException, NotFoundException { VerifiedYieldContractDto dto = verifiedYieldContractDao.fetch(verifiedYieldContract.getVerifiedYieldContractGuid()); diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/model/factory/VerifiedYieldContractFactory.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/model/factory/VerifiedYieldContractFactory.java index f0422a6b..0573ba05 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/model/factory/VerifiedYieldContractFactory.java +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/model/factory/VerifiedYieldContractFactory.java @@ -1,36 +1,46 @@ package ca.bc.gov.mal.cirras.underwriting.service.api.v1.model.factory; +import ca.bc.gov.nrs.wfone.common.model.Message; import ca.bc.gov.nrs.wfone.common.service.api.model.factory.FactoryContext; import ca.bc.gov.nrs.wfone.common.service.api.model.factory.FactoryException; import ca.bc.gov.nrs.wfone.common.webade.authentication.WebAdeAuthentication; +import java.util.List; + import ca.bc.gov.mal.cirras.underwriting.model.v1.AnnualField; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContract; import ca.bc.gov.mal.cirras.underwriting.model.v1.VerifiedYieldContractCommodity; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.DeclaredYieldContractDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.PolicyDto; +import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.ProductDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldContractCommodityDto; import ca.bc.gov.mal.cirras.underwriting.persistence.v1.dto.VerifiedYieldContractDto; public interface VerifiedYieldContractFactory { - VerifiedYieldContract getDefaultVerifiedYieldContract( + VerifiedYieldContract getDefaultVerifiedYieldContract( PolicyDto policyDto, DeclaredYieldContractDto dycDto, + List productDtos, FactoryContext context, WebAdeAuthentication authentication ) throws FactoryException; - VerifiedYieldContract getVerifiedYieldContract( + VerifiedYieldContract getVerifiedYieldContract( VerifiedYieldContractDto dto, + List productDtos, FactoryContext context, WebAdeAuthentication authentication ) throws FactoryException; void updateDto( VerifiedYieldContractDto dto, - VerifiedYieldContract model, + VerifiedYieldContract model, String userId); - void updateDto(VerifiedYieldContractCommodityDto dto, VerifiedYieldContractCommodity model); + void updateDto( + VerifiedYieldContractCommodityDto dto, + VerifiedYieldContractCommodity model, + List productDtos, + Boolean updateProductValues); } diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/reports/JasperReportService.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/reports/JasperReportService.java index 3341da21..28882f7d 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/reports/JasperReportService.java +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/reports/JasperReportService.java @@ -14,8 +14,10 @@ public interface JasperReportService byte[] generateInvForageReport(Map paramMap) throws JasperReportServiceException; - byte[] generateInvGrainReport(Map paramMap) throws JasperReportServiceException; + byte[] generateUnseededGrainReport(Map paramMap) throws JasperReportServiceException; + byte[] generateSeededGrainReport(Map paramMap) throws JasperReportServiceException; + void setReportServiceUrl(String reportServiceUrl); void setReportServicePassword(String reportServicePassword); diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/reports/JasperReportServiceImpl.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/reports/JasperReportServiceImpl.java index 5b2397f1..a73b516c 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/reports/JasperReportServiceImpl.java +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/reports/JasperReportServiceImpl.java @@ -65,11 +65,17 @@ public byte[] generateInvForageReport(Map paramMap) throws Jaspe } @Override - public byte[] generateInvGrainReport(Map paramMap) throws JasperReportServiceException { - byte[] reportContent = generateJasperReportInMemory("CUWS_Inventory_Grain", paramMap); + public byte[] generateUnseededGrainReport(Map paramMap) throws JasperReportServiceException { + byte[] reportContent = generateJasperReportInMemory("CUWS_Unseeded_Grain", paramMap); return reportContent; } + @Override + public byte[] generateSeededGrainReport(Map paramMap) throws JasperReportServiceException { + byte[] reportContent = generateJasperReportInMemory("CUWS_Seeded_Grain", paramMap); + return reportContent; + } + private byte[] generateJasperReportInMemory(String reportName, Map paramMap) throws JasperReportServiceException { // Check config settings. diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/spring/ServiceApiSpringConfig.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/spring/ServiceApiSpringConfig.java index 700c2b78..966e3fdb 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/spring/ServiceApiSpringConfig.java +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/spring/ServiceApiSpringConfig.java @@ -403,6 +403,7 @@ public CirrasVerifiedYieldService cirrasVerifiedYieldService() { result.setVerifiedYieldContractDao(persistenceSpringConfig.verifiedYieldContractDao()); result.setVerifiedYieldContractCommodityDao(persistenceSpringConfig.verifiedYieldContractCommodityDao()); result.setVerifiedYieldAmendmentDao(persistenceSpringConfig.verifiedYieldAmendmentDao()); + result.setProductDao(persistenceSpringConfig.productDao()); return result; } diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/util/CommodityCoverageCode.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/util/CommodityCoverageCode.java new file mode 100644 index 00000000..7776094f --- /dev/null +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/util/CommodityCoverageCode.java @@ -0,0 +1,25 @@ +package ca.bc.gov.mal.cirras.underwriting.service.api.v1.util; + +public class CommodityCoverageCode { + public static final String QUANTITY_FORAGE = "CQF"; + public static final String QUANTITY_SILAGE_CORN = "CQSC"; + public static final String PLANT = "CPLANT"; + public static final String GRAIN_SPOT_LOSS = "CSL"; + public static final String QUANTITY_GRAIN = "CQG"; + public static final String QUANTITY = "CQNT"; + public static final String OTHER = "COTH"; + public static final String LOT_HAIL_RAIN = "CLHR"; + public static final String HAIL_RAIN = "CHAIL"; + public static final String CROP_UNSEEDED = "CUNS"; + public static final String ACREAGE_LOSS = "CAL"; + public static final String PLANT_TREE_FRUIT = "CPTF"; + public static final String QUANTITY_TREE_FRUIT = "CQTF"; + public static final String GRAIN_BASKET = "GB"; + public static final String FORAGE_SUPPLY = "FS"; + public static final String AWP = "AWP"; + public static final String AWP_EXCRETA = "AWPE"; + public static final String SPECIAL_TC = "STC"; + public static final String SPECIAL_BU = "SBU"; + public static final String YOUNG_PLANT = "YP"; + public static final String QUANTITY_TREE_FRUIT_NET_PRODUCTION = "CQTFN"; +} diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/util/InventoryServiceEnums.java b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/util/InventoryServiceEnums.java index 57250aa4..63a7c5ba 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/util/InventoryServiceEnums.java +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/java/ca/bc/gov/mal/cirras/underwriting/service/api/v1/util/InventoryServiceEnums.java @@ -54,5 +54,10 @@ public enum LinkPlantingType{ ADD_LINK, REMOVE_LINK } - + + // Valid options for reportType parameter for Grain Inventory Report. + public enum InventoryReportType { + unseeded, + seeded; + } } diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/reports/CUWS_Seeded_Grain.jrxml b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/reports/CUWS_Seeded_Grain.jrxml new file mode 100644 index 00000000..10c44aa7 --- /dev/null +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/reports/CUWS_Seeded_Grain.jrxml @@ -0,0 +1,1020 @@ + + + + + + + + + + + + + + + + + + + 0 + and p.policy_id::text in (select regexp_split_to_table($P{p_policy_ids}, ',')) + union + --POLICY AND FIELDS WITH FILTER + select distinct p.policy_id + , p.contract_id + , p.policy_number + , p.crop_year + , g.grower_number + , g.grower_name + , ic.inventory_contract_guid + , ic.inv_update_timestamp + , ic.fertilizer_ind + , ic.herbicide_ind + , ic.tilliage_ind + , ic.other_changes_ind + , ic.other_changes_comment + , ic.grain_from_prev_year_ind + , ifd.inventory_field_guid + , iu.acres_to_be_seeded + , iu.is_unseeded_insurable_ind + from policy p + join grower g on g.grower_id = p.grower_id + join grower_contract_year gcy on gcy.contract_id = p.contract_id + and gcy.crop_year = p.crop_year + join inventory_contract ic on ic.contract_id = gcy.contract_id + and ic.crop_year = gcy.crop_year + join contracted_field_detail cfd on cfd.grower_contract_year_id = gcy.grower_contract_year_id + join annual_field_detail afd on afd.annual_field_detail_id = cfd.annual_field_detail_id + join field f on afd.field_id = f.field_id + left join legal_land ll on ll.legal_land_id = afd.legal_land_id + join inventory_field ifd on ifd.field_id = f.field_id + and ifd.insurance_plan_id = gcy.insurance_plan_id + and ifd.crop_year = afd.crop_year + left join inventory_unseeded iu on iu.inventory_field_guid = ifd.inventory_field_guid + left join inventory_seeded_grain isg on isg.inventory_field_guid = ifd.inventory_field_guid + left join grower_contact gc on gc.grower_id = g.grower_id + left join contact c on c.contact_id = gc.contact_id + left join contact_email ce on ce.contact_id = c.contact_id + left join contact_phone cp on cp.contact_id = c.contact_id + where ifd.is_hidden_on_printout_ind = 'N' + and ($P{p_policy_ids} is null or char_length($P{p_policy_ids}) = 0) + and + ( + case + when $P{p_crop_year} is not null then p.crop_year = $P{p_crop_year} + else true + end + ) + and + ( + case + when $P{p_insurance_plan_id} is not null then p.insurance_plan_id = $P{p_insurance_plan_id} + else true + end + ) + and + ( + case + when $P{p_policy_status_code} is not null and char_length($P{p_policy_status_code}) > 0 then p.policy_status_code = $P{p_policy_status_code} + else true + end + ) + and + ( + case + when $P{p_office_id} is not null then p.office_id = $P{p_office_id} + else true + end + ) + and + ( + case + when $P{p_policy_number} is not null and char_length($P{p_policy_number}) > 0 then p.policy_number like $P{p_policy_number} + else true + end + ) + and + ( + case + when $P{p_grower_info} is not null and char_length($P{p_grower_info}) > 0 + then + g.grower_number::text like $P{p_grower_info} + or upper(g.grower_name) like $P{p_grower_info} + or upper(ce.email_address) like $P{p_grower_info} + or + ( + case + when $P{p_grower_phone_number} is not null and char_length($P{p_grower_phone_number}) > 0 + then + cp.phone_number like $P{p_grower_phone_number} + else false + end + ) + else true + end + ) +) t +group by t.policy_id + , t.contract_id + , t.policy_number + , t.crop_year + , t.grower_number + , t.grower_name + , t.inventory_contract_guid + , t.inv_update_timestamp + , t.fertilizer_ind + , t.herbicide_ind + , t.tilliage_ind + , t.other_changes_ind + , t.other_changes_comment + , t.grain_from_prev_year_ind +order by sort_column, + t.policy_number]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $P{p_top_planting_limit} ? "X" : ""]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $P{p_top_planting_limit}]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + $P{p_top_planting_limit} ? "N" : "Y"]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/reports/CUWS_Inventory_Grain.jrxml b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/reports/CUWS_Unseeded_Grain.jrxml similarity index 99% rename from cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/reports/CUWS_Inventory_Grain.jrxml rename to cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/reports/CUWS_Unseeded_Grain.jrxml index c3af7059..36f42d32 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/reports/CUWS_Inventory_Grain.jrxml +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/reports/CUWS_Unseeded_Grain.jrxml @@ -1,6 +1,6 @@ - + @@ -919,7 +919,7 @@ order by sort_column, - + @@ -990,7 +990,7 @@ order by sort_column, - + @@ -1017,4 +1017,4 @@ order by sort_column, - \ No newline at end of file + diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Inv_Grain_Acres_Seeded.jrxml b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Inv_Grain_Acres_Seeded.jrxml index f73edf3c..ec452b10 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Inv_Grain_Acres_Seeded.jrxml +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Inv_Grain_Acres_Seeded.jrxml @@ -6,36 +6,65 @@ - + 0 + and ic.contract_id = $P{p_contract_id} + and ic.crop_year = $P{p_crop_year} + group by ic.contract_id, + ic.crop_year + ) +select INITCAP(cc.commodity_name) as commodity_name, + icc.is_pedigree_ind, + icc.total_seeded_acres +from inventory_contract_commodity icc +join crop_commodity cc on cc.crop_commodity_id = icc.crop_commodity_id +join inventory_contract ic on ic.inventory_contract_guid = icc.inventory_contract_guid +join seeded_inv on seeded_inv.contract_id = ic.contract_id + and seeded_inv.crop_year = ic.crop_year +where seeded_inv.num_seedings > 0 + and icc.total_seeded_acres > 0 + and ic.contract_id = $P{p_contract_id} + and ic.crop_year = $P{p_crop_year} +union +select INITCAP(cc.commodity_name) as commodity_name, + 'N' as is_pedigree_ind, + null as total_seeded_acres +from crop_commodity cc +left join seeded_inv on seeded_inv.contract_id = $P{p_contract_id} + and seeded_inv.crop_year = $P{p_crop_year} +where (seeded_inv.num_seedings is null or seeded_inv.num_seedings = 0) + and cc.insurance_plan_id = 4 + and cc.is_crop_insurance_eligible_ind = 'Y' + and cc.is_inventory_crop_ind = 'Y' +order by commodity_name, is_pedigree_ind +]]> - - - + + + + + + + - + @@ -76,7 +105,7 @@ order by commodity_name]]> - + @@ -94,11 +123,12 @@ order by commodity_name]]> - + @@ -136,7 +166,7 @@ order by commodity_name]]> - - \ No newline at end of file + diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Sdd_Grain_Plantings.jrxml b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Sdd_Grain_Plantings.jrxml new file mode 100644 index 00000000..7cebe1d0 --- /dev/null +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Sdd_Grain_Plantings.jrxml @@ -0,0 +1,869 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Inv_Grain_Plantings.jrxml b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Unsdd_Grain_Plantings.jrxml similarity index 98% rename from cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Inv_Grain_Plantings.jrxml rename to cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Unsdd_Grain_Plantings.jrxml index ed8c4395..1acd9ed8 100644 --- a/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Inv_Grain_Plantings.jrxml +++ b/cirras-underwriting-api/cirras-underwriting-service-api/src/main/resources/subreports/CUWS_Unsdd_Grain_Plantings.jrxml @@ -1,6 +1,6 @@ - + @@ -42,7 +42,8 @@ , INITCAP(cv.variety_name) as seeded_variety_name , isg.seeded_acres , isg.seeding_date - , INITCAP(cv_underseeded.variety_name) as underseeded_variety_name + , INITCAP(cv_underseeded.variety_name) as underseeded_variety_name + , isg.is_pedigree_ind from grower_contract_year gcy join inventory_contract ic on ic.contract_id = gcy.contract_id and ic.crop_year = gcy.crop_year @@ -169,6 +170,10 @@ offset $P{p_record_offset}]]> + + + + @@ -767,7 +772,9 @@ offset $P{p_record_offset}]]> - + diff --git a/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/cirras.cuws.03_06_00_00.ddl.json b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/cirras.cuws.03_06_00_00.ddl.json index 0f6e43d8..6b5d0430 100644 --- a/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/cirras.cuws.03_06_00_00.ddl.json +++ b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/cirras.cuws.03_06_00_00.ddl.json @@ -6,6 +6,8 @@ {"sqlFile": {"relativeToChangelogFile": "true", "path": "ddl/tables/cuws.create.verified_yield_contract_commodity.sql"}}, {"sqlFile": {"relativeToChangelogFile": "true", "path": "ddl/tables/cuws.create.verified_yield_amendment_code.sql"}}, {"sqlFile": {"relativeToChangelogFile": "true", "path": "ddl/tables/cuws.create.verified_yield_amendment.sql"}}, + {"sqlFile": {"relativeToChangelogFile": "true", "path": "ddl/tables/cuws.create.verified_yield_summary.sql"}}, + {"sqlFile": {"relativeToChangelogFile": "true", "path": "ddl/tables/cuws.alter.underwriting_comment.sql"}}, {"sqlFile": {"relativeToChangelogFile": "true", "path": "ddl/tables/cuws.create.product.sql"}}, {"sqlFile": {"relativeToChangelogFile": "true", "path": "ddl/tables/cuws.create.crop_commodity_pedigree_xref.sql"}}, {"sqlFile": {"relativeToChangelogFile": "true", "path": "ddl/grants/cuws.ddl.apply_grants.sql"}} diff --git a/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/grants/cuws.ddl.apply_grants.sql b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/grants/cuws.ddl.apply_grants.sql index 3a8f4163..1f2e9e24 100644 --- a/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/grants/cuws.ddl.apply_grants.sql +++ b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/grants/cuws.ddl.apply_grants.sql @@ -4,6 +4,7 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON cuws.verified_yield_contract TO "app_cuw GRANT SELECT, INSERT, UPDATE, DELETE ON cuws.verified_yield_contract_commodity TO "app_cuws_rest_proxy"; GRANT SELECT, INSERT, UPDATE, DELETE ON cuws.verified_yield_amendment_code TO "app_cuws_rest_proxy"; GRANT SELECT, INSERT, UPDATE, DELETE ON cuws.verified_yield_amendment TO "app_cuws_rest_proxy"; +GRANT SELECT, INSERT, UPDATE, DELETE ON cuws.verified_yield_summary TO "app_cuws_rest_proxy"; GRANT SELECT, INSERT, UPDATE, DELETE ON cuws.product TO "app_cuws_rest_proxy"; GRANT SELECT, INSERT, UPDATE, DELETE ON cuws.crop_commodity_pedigree_xref TO "app_cuws_rest_proxy"; diff --git a/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/tables/cuws.alter.underwriting_comment.sql b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/tables/cuws.alter.underwriting_comment.sql new file mode 100644 index 00000000..520e8727 --- /dev/null +++ b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/tables/cuws.alter.underwriting_comment.sql @@ -0,0 +1,13 @@ +ALTER TABLE cuws.underwriting_comment ADD COLUMN verified_yield_summary_guid varchar(32); + +COMMENT ON COLUMN cuws.underwriting_comment.verified_yield_summary_guid IS 'Verified Yield Summary GUID is the primary key used to identify the record' +; + +CREATE INDEX ix_uc_vys ON cuws.underwriting_comment(verified_yield_summary_guid) + TABLESPACE pg_default +; + +ALTER TABLE cuws.underwriting_comment ADD CONSTRAINT fk_uc_vys + FOREIGN KEY (verified_yield_summary_guid) + REFERENCES cuws.verified_yield_summary(verified_yield_summary_guid) +; \ No newline at end of file diff --git a/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/tables/cuws.create.verified_yield_summary.sql b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/tables/cuws.create.verified_yield_summary.sql new file mode 100644 index 00000000..da1f3721 --- /dev/null +++ b/cirras-underwriting-liquibase/scripts/03_00_xx/03_06_00/00/ddl/tables/cuws.create.verified_yield_summary.sql @@ -0,0 +1,82 @@ +CREATE TABLE cuws.verified_yield_summary( + verified_yield_summary_guid varchar(32) NOT NULL, + verified_yield_contract_guid varchar(32) NOT NULL, + crop_commodity_id numeric(9, 0) NOT NULL, + is_pedigree_ind varchar(1) NOT NULL, + harvested_yield numeric(14, 4), + harvested_yield_per_acre numeric(14, 4), + appraised_yield numeric(14, 4), + assessed_yield numeric(14, 4), + yield_to_count numeric(14, 4), + yield_percent_py numeric(14, 4), + production_guarantee numeric(14, 4), + probable_yield numeric(14, 4), + create_user varchar(64) NOT NULL, + create_date timestamp(0) NOT NULL, + update_user varchar(64) NOT NULL, + update_date timestamp(0) NOT NULL +) TABLESPACE pg_default +; + + + +COMMENT ON COLUMN cuws.verified_yield_summary.verified_yield_summary_guid IS 'Verified Yield Summary GUID is the primary key used to identify the record' +; +COMMENT ON COLUMN cuws.verified_yield_summary.verified_yield_contract_guid IS 'Verified Yield Contract GUID is the primary key used to identify the record' +; +COMMENT ON COLUMN cuws.verified_yield_summary.crop_commodity_id IS 'Crop Commodity Id is a unique Id of a commodity from cirr_crop_types.crpt_id' +; +COMMENT ON COLUMN cuws.verified_yield_summary.is_pedigree_ind IS 'Is Pedigree Ind determines if the yield is for a pedigree crop (Y) or (N).' +; +COMMENT ON COLUMN cuws.verified_yield_summary.harvested_yield IS 'Harvested Yield is either verified_yield_contract_commodity.harvested_yield or verified_yield_contract_commodity.harvested_yield_override if it exists.' +; +COMMENT ON COLUMN cuws.verified_yield_summary.harvested_yield_per_acre IS 'Harvested Yield per Acre matches verified_yield_contract_commodity.yield_per_acre.' +; +COMMENT ON COLUMN cuws.verified_yield_summary.appraised_yield IS 'Appraised Yield is calculated as SUM(verified_yield_amendment.yield_per_acre * acres) where commodity and is_pedigree_ind match and if type is appraised.' +; +COMMENT ON COLUMN cuws.verified_yield_summary.assessed_yield IS 'Assessed Yield is calculated as SUM(verified_yield_amendment.yield_per_ac * acres) where commodity matches and if type is assessed' +; +COMMENT ON COLUMN cuws.verified_yield_summary.yield_to_count IS 'Yield to Count is calculated as the SUM(Harvested Yield, Appraised Yield) from this table' +; +COMMENT ON COLUMN cuws.verified_yield_summary.yield_percent_py IS 'Yield Percent of PY is calculated as (Yield to Count/(Insured Acres * PY)) where Probable Yield is taken from the value of active product matching the commodity from CIRRAS' +; +COMMENT ON COLUMN cuws.verified_yield_summary.production_guarantee IS 'Production Guarantee is taken from CIRR_INSRNC_PRDCT_PRCHSES.Q_PRODUCTION_GUARANTEE' +; +COMMENT ON COLUMN cuws.verified_yield_summary.probable_yield IS 'Probable Yield is taken from CIRR_INSURABLE_CROP_UNITS.PROBABLE_YIELD' +; +COMMENT ON COLUMN cuws.verified_yield_summary.create_user IS 'Create User is the user id of the user that created the record.' +; +COMMENT ON COLUMN cuws.verified_yield_summary.create_date IS 'Create Date is the date when the record was created.' +; +COMMENT ON COLUMN cuws.verified_yield_summary.update_user IS 'Update User is the user id of the user that updated the record last.' +; +COMMENT ON COLUMN cuws.verified_yield_summary.update_date IS 'Update Date is the date when the record was updated last.' +; +COMMENT ON TABLE cuws.verified_yield_summary IS 'The table contains verified yield summary data by contract and commodity.' +; + +CREATE INDEX ix_vys_vyc ON cuws.verified_yield_summary(verified_yield_contract_guid) + TABLESPACE pg_default +; +CREATE INDEX ix_vys_cco ON cuws.verified_yield_summary(crop_commodity_id) + TABLESPACE pg_default +; +ALTER TABLE cuws.verified_yield_summary ADD + CONSTRAINT pk_vys PRIMARY KEY (verified_yield_summary_guid) USING INDEX TABLESPACE pg_default +; + +ALTER TABLE cuws.verified_yield_summary ADD + CONSTRAINT uk_vys UNIQUE (verified_yield_contract_guid, crop_commodity_id, is_pedigree_ind) USING INDEX TABLESPACE pg_default +; + +ALTER TABLE cuws.verified_yield_summary ADD CONSTRAINT fk_vys_vyc + FOREIGN KEY (verified_yield_contract_guid) + REFERENCES cuws.verified_yield_contract(verified_yield_contract_guid) +; + +ALTER TABLE cuws.verified_yield_summary ADD CONSTRAINT fk_vys_cco + FOREIGN KEY (crop_commodity_id) + REFERENCES cuws.crop_commodity(crop_commodity_id) +; + + diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/forage/forage-inventory.component.ts b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/forage/forage-inventory.component.ts index 3bf06ba7..6358a0b2 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/forage/forage-inventory.component.ts +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/forage/forage-inventory.component.ts @@ -1463,7 +1463,7 @@ isFormValid() { onPrint() { let reportName = replaceNonAlphanumericCharacters(this.growerContract.growerName) + "-Inventory" - this.store.dispatch(GetInventoryReport(reportName, this.policyId, "", INSURANCE_PLAN.FORAGE.toString(), "", "", "", "", "")) + this.store.dispatch(GetInventoryReport(reportName, this.policyId, "", INSURANCE_PLAN.FORAGE.toString(), "", "", "", "", "", "")) } diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-inventory.component.ts b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-inventory.component.ts index 5bafed0b..0e1ad75a 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-inventory.component.ts +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-inventory.component.ts @@ -990,9 +990,9 @@ ngOnChanges2(changes: SimpleChanges) { } - onPrint() { + onPrint(reportType) { let reportName = replaceNonAlphanumericCharacters(this.growerContract.growerName) + "-Inventory" - this.store.dispatch(GetInventoryReport(reportName, this.policyId, "", INSURANCE_PLAN.GRAIN.toString(), "", "", "", "", "")) + this.store.dispatch(GetInventoryReport(reportName, this.policyId, "", INSURANCE_PLAN.GRAIN.toString(), "", "", "", "", "", reportType)) } diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-seeded/grain-seeded-inventory.component.html b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-seeded/grain-seeded-inventory.component.html index a2f593a2..3d9a309b 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-seeded/grain-seeded-inventory.component.html +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-seeded/grain-seeded-inventory.component.html @@ -27,7 +27,7 @@
diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-unseeded/grain-unseeded-inventory.component.html b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-unseeded/grain-unseeded-inventory.component.html index 7348abac..1ac614fb 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-unseeded/grain-unseeded-inventory.component.html +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/inventory/grain/grain-unseeded/grain-unseeded-inventory.component.html @@ -26,7 +26,7 @@
diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-button/reports-download-button.component.ts b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-button/reports-download-button.component.ts index a4338a11..a15a6c36 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-button/reports-download-button.component.ts +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-button/reports-download-button.component.ts @@ -13,7 +13,7 @@ import { GetDopReport } from "src/app/store/dop/dop.actions"; styleUrls: ['./reports-download-button.component.scss'] }) export class ReportsDownloadButtonComponent { - @Input() reportType: string; + @Input() reportChoice: string; @Input() policyId: string; @Input() cropYear: string; @Input() insurancePlanId: string; @@ -32,7 +32,10 @@ export class ReportsDownloadButtonComponent { onReportPrint() { const dialogRef = this.dialog.open(ReportsDownloadDialogComponent, { width: '341px', - data: null, + data: { + insurancePlanId: this.insurancePlanId, + reportChoice: this.reportChoice + }, autoFocus: false, closeOnNavigation: false, panelClass: 'wf-dialog' @@ -41,9 +44,9 @@ export class ReportsDownloadButtonComponent { const self = this; dialogRef.afterClosed().subscribe(result => { if (result?.event == 'Download' && self.isSearchValid()) { - switch (this.reportType) { + switch (this.reportChoice) { case REPORT_CHOICES.INVENTORY: - self.inventoryBatchPrint(result.sortColumn); + self.inventoryBatchPrint(result.sortColumn, result.reportType); break; case REPORT_CHOICES.DOP: self.dopReportPrint(result.sortColumn); @@ -69,7 +72,7 @@ export class ReportsDownloadButtonComponent { return false } - inventoryBatchPrint(sortColumn: string) { + inventoryBatchPrint(sortColumn: string, reportType: string) { this.store.dispatch(GetInventoryReport("Inventory-batch.pdf", this.policyId, this.cropYear, @@ -78,7 +81,8 @@ export class ReportsDownloadButtonComponent { this.policyStatusCode, this.policyNumber, this.growerInfo, - sortColumn + sortColumn, + reportType )); } diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-dialog/reports-download-dialog.component.html b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-dialog/reports-download-dialog.component.html index 7810960f..b6927b81 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-dialog/reports-download-dialog.component.html +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-dialog/reports-download-dialog.component.html @@ -1,5 +1,16 @@
+ + Report Type + + + + {{option.description}} + + + + + Sort By @@ -12,7 +23,7 @@
- diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-dialog/reports-download-dialog.component.ts b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-dialog/reports-download-dialog.component.ts index f6be1c26..31fade94 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-dialog/reports-download-dialog.component.ts +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/reports/reports-download-dialog/reports-download-dialog.component.ts @@ -1,7 +1,7 @@ import { Component, Inject, OnInit } from "@angular/core"; import { MAT_DIALOG_DATA, MatDialogRef } from "@angular/material/dialog"; import { DIALOG_TYPE } from "../../dialogs/base-dialog/base-dialog.component"; -import { REPORT_SORT_BY, SORT_BY_CHOICES } from "src/app/utils/constants"; +import { INSURANCE_PLAN, REPORT_CHOICES, REPORT_SORT_BY, REPORT_TYPE_OPTIONS, SORT_BY_CHOICES } from "src/app/utils/constants"; @Component({ selector: 'reports-download-dialog', @@ -12,25 +12,62 @@ export class ReportsDownloadDialogComponent implements OnInit { titleLabel = "Report Details"; dialogType = DIALOG_TYPE.INFO; + dataReceived: any; + reportSortByOptions: any; selectedReportSortBy: string; + reportTypeOptions: any; + selectedReportType = ""; + constructor(public dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: any) { } + @Inject(MAT_DIALOG_DATA) public data: any) { + if (data) { + //capture the data that comes from the main page + this.dataReceived = data; + } + } ngOnInit(): void { this.reportSortByOptions = REPORT_SORT_BY; + this.reportTypeOptions = REPORT_TYPE_OPTIONS; } onSelectionChange(event) { this.selectedReportSortBy = event.value; } + onReportTypeSelectionChange(event) { + this.selectedReportType = event.value; + } + onCancel() { this.dialogRef.close({ event: 'Cancel' }); } onDownload() { - this.dialogRef.close({ event: 'Download', sortColumn: this.selectedReportSortBy || SORT_BY_CHOICES.POLICY_NUMBER }); + this.dialogRef.close({ event: 'Download', sortColumn: this.selectedReportSortBy || SORT_BY_CHOICES.POLICY_NUMBER , reportType: this.selectedReportType}); + } + + isGrainInventoryReport(){ + if (this.dataReceived && this.dataReceived.insurancePlanId == INSURANCE_PLAN.GRAIN && this.dataReceived.reportChoice == REPORT_CHOICES.INVENTORY ) { + return true + } else { + return false + } } + + isDownloadPossible(){ + + if (!this.selectedReportSortBy) { + return false + } + + if (this.isGrainInventoryReport() && this.selectedReportType == "") { + return false + } + + return true + } + } \ No newline at end of file diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/uw-contracts-list/uw-contracts-list.component.html b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/uw-contracts-list/uw-contracts-list.component.html index edf84d4c..883c6672 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/uw-contracts-list/uw-contracts-list.component.html +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/uw-contracts-list/uw-contracts-list.component.html @@ -10,7 +10,7 @@

Policies

{{ countSelectedRecords }} Selected diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/verified-yield/commodity-list/verified-yield-commodity-list.component.ts b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/verified-yield/commodity-list/verified-yield-commodity-list.component.ts index 3ef50704..a4b34e82 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/verified-yield/commodity-list/verified-yield-commodity-list.component.ts +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/verified-yield/commodity-list/verified-yield-commodity-list.component.ts @@ -14,7 +14,7 @@ export class VerifiedYieldCommodityListComponent { @Input() commoditiesFormArray: UntypedFormArray; @Input() isUnsaved: boolean; - yieldCalculatorLink = "ms-excel:ofe|u|https://bcgov.sharepoint.com/sites/AF-BRMB-DATA/Shared%20Documents/PI%20Grain%20Yield%20&%20Claim%20Calculator.xlsm" + yieldCalculatorLink = "ms-excel:ofe|u|https://bcgov.sharepoint.com/sites/AF-BRMB-DATA/Shared%20Documents/Yield%20Calculators/PI%20Grain%20Yield%20&%20Claim%20Calculator.xlsm" goToYieldCalculatorLink(){ diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/verified-yield/commodity/verified-yield-commodity.component.ts b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/verified-yield/commodity/verified-yield-commodity.component.ts index 7bc2176b..fdd0ac9b 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/verified-yield/commodity/verified-yield-commodity.component.ts +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/components/verified-yield/commodity/verified-yield-commodity.component.ts @@ -77,7 +77,9 @@ export class VerifiedYieldCommodityComponent implements OnChanges { onDeleteCommodity() { this.commodityFormGroup.controls['harvestedAcresOverride'].setValue('') this.commodityFormGroup.controls['harvestedYieldOverride'].setValue('') - + this.commodity.harvestedAcresOverride = null + this.commodity.harvestedYieldOverride = null + this.store.dispatch(setFormStateUnsaved(VERIFIED_YIELD_COMPONENT_ID, true)); } diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/store/inventory/inventory.actions.ts b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/store/inventory/inventory.actions.ts index 97314804..536e809d 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/store/inventory/inventory.actions.ts +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/store/inventory/inventory.actions.ts @@ -153,6 +153,7 @@ export interface GetInventoryReportAction extends Action { policyNumber: string; growerInfo: string; sortColumn: string; + reportType: string; } } @@ -164,7 +165,8 @@ export function GetInventoryReport(reportName: string, policyStatusCode: string, policyNumber: string, growerInfo: string, - sortColumn: string): GetInventoryReportAction { + sortColumn: string, + reportType: string): GetInventoryReportAction { return { type: GET_INVENTORY_REPORT_BYTES, payload: { @@ -176,7 +178,8 @@ export function GetInventoryReport(reportName: string, policyStatusCode: policyStatusCode, policyNumber: policyNumber, growerInfo: growerInfo, - sortColumn: sortColumn + sortColumn: sortColumn, + reportType: reportType } }; } diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/store/inventory/inventory.effects.ts b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/store/inventory/inventory.effects.ts index e3f80f2e..37112e58 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/store/inventory/inventory.effects.ts +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/store/inventory/inventory.effects.ts @@ -221,10 +221,11 @@ getInventoryReportBytes: Observable = createEffect (() => this.actions. let policyNumber = typedAction.payload.policyNumber ? typedAction.payload.policyNumber : ""; let growerInfo = typedAction.payload.growerInfo ? typedAction.payload.growerInfo : ""; let sortColumn = typedAction.payload.sortColumn ? typedAction.payload.sortColumn : ""; - + let reportType = typedAction.payload.reportType ? typedAction.payload.reportType : ""; + let endpoint = this.appConfig.getConfig().rest["cirras_underwriting"] +"/inventoryContracts/report?policyIds=" + policyId + "&cropYear=" + cropYear + "&insurancePlanId=" + insurancePlanId + "&officeId=" + officeId + "&policyStatusCode=" + policyStatusCode + - "&policyNumber=" + policyNumber + "&growerInfo=" + encodeURI(growerInfo) + "&sortColumn=" + sortColumn + "&policyNumber=" + policyNumber + "&growerInfo=" + encodeURI(growerInfo) + "&sortColumn=" + sortColumn + "&reportType=" + reportType return this.httpClient .get(endpoint, {observe: 'response', responseType:'blob'}) diff --git a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/utils/constants.ts b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/utils/constants.ts index e3cdcc70..e14bc3e7 100644 --- a/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/utils/constants.ts +++ b/cirras-underwriting-war/cirras-underwriting-war/src/main/angular/src/app/utils/constants.ts @@ -105,6 +105,16 @@ export const SORT_BY_CHOICES = { POLICY_NUMBER: "policyNumber", GROWER_NAME: "growerName", } +export const REPORT_TYPE_OPTIONS = [ + { + code: "unseeded", + description: "Unseeded Inventory" + }, + { + code: "seeded", + description: "Seeded Inventory" + }, +]; export const BASE_COMMODITIES = ['BARLEY', 'CANOLA', 'FALL RYE', 'FIELD PEA', 'OAT', 'WHEAT', 'WINTER WHEAT']