Repository: incubator-fineract
Updated Branches:
  refs/heads/develop fe6e1e88f -> 60588a78e


http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/60588a78/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/serialization/ShareProductDataSerializer.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/serialization/ShareProductDataSerializer.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/serialization/ShareProductDataSerializer.java
index 345294b..02c08d9 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/serialization/ShareProductDataSerializer.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/serialization/ShareProductDataSerializer.java
@@ -39,6 +39,7 @@ import 
org.apache.fineract.infrastructure.core.serialization.FromJsonHelper;
 import org.apache.fineract.infrastructure.core.service.DateUtils;
 import 
org.apache.fineract.infrastructure.security.service.PlatformSecurityContext;
 import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
+import 
org.apache.fineract.portfolio.accounts.constants.ShareAccountApiConstants;
 import org.apache.fineract.portfolio.charge.domain.Charge;
 import org.apache.fineract.portfolio.charge.domain.ChargeRepositoryWrapper;
 import org.apache.fineract.portfolio.common.domain.PeriodFrequencyType;
@@ -102,14 +103,18 @@ public class ShareProductDataSerializer {
         Long totalNumberOfShares = 
this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.totalshares_paramname,
 element);
         
baseDataValidator.reset().parameter(ShareProductApiConstants.totalshares_paramname).value(totalNumberOfShares).notNull()
                 .longGreaterThanZero();
-
+        final Long sharesIssued = 
this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.totalsharesissued_paramname,
 element);
+        if(sharesIssued != null && totalNumberOfShares != null && sharesIssued 
> totalNumberOfShares) {
+            
baseDataValidator.reset().parameter(ShareProductApiConstants.totalsharesissued_paramname).value(sharesIssued)
+            
.failWithCodeNoParameterAddedToErrorCode("sharesIssued.cannot.be.greater.than.totalNumberOfShares");
+        }
         final String currencyCode = 
this.fromApiJsonHelper.extractStringNamed(ShareProductApiConstants.currency_paramname,
 element);
         final Integer digitsAfterDecimal = 
this.fromApiJsonHelper.extractIntegerWithLocaleNamed(
                 ShareProductApiConstants.digitsafterdecimal_paramname, 
element);
         final Integer inMultiplesOf = 
this.fromApiJsonHelper.extractIntegerWithLocaleNamed(
                 ShareProductApiConstants.inmultiplesof_paramname, element);
         final MonetaryCurrency currency = new MonetaryCurrency(currencyCode, 
digitsAfterDecimal, inMultiplesOf);
-        final Long sharesIssued = 
this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.totalsharesissued_paramname,
 element);
+      
         final BigDecimal unitPrice = 
this.fromApiJsonHelper.extractBigDecimalNamed(ShareProductApiConstants.unitprice_paramname,
 element,
                 locale);
         
baseDataValidator.reset().parameter(ShareProductApiConstants.unitprice_paramname).value(unitPrice).notNull().positiveAmount();
@@ -132,12 +137,12 @@ public class ShareProductDataSerializer {
         Long nominalClientShares = 
this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.nominaltshares_paramname,
 element);
         
baseDataValidator.reset().parameter(ShareProductApiConstants.nominaltshares_paramname).value(nominalClientShares).notNull()
                 .longGreaterThanZero();
-        if (minimumClientShares != null && nominalClientShares != null) {
+        if (minimumClientShares != null && nominalClientShares != null && 
!minimumClientShares.equals(nominalClientShares)) {
             
baseDataValidator.reset().parameter(ShareProductApiConstants.nominaltshares_paramname).value(nominalClientShares)
                     .longGreaterThanNumber(minimumClientShares);
         }
         Long maximumClientShares = 
this.fromApiJsonHelper.extractLongNamed(ShareProductApiConstants.maximumshares_paramname,
 element);
-        if (maximumClientShares != null && nominalClientShares != null) {
+        if (maximumClientShares != null && nominalClientShares != null && 
!maximumClientShares.equals(nominalClientShares)) {
             
baseDataValidator.reset().parameter(ShareProductApiConstants.maximumshares_paramname).value(maximumClientShares)
                     .longGreaterThanNumber(nominalClientShares);
         }
@@ -294,8 +299,16 @@ public class ShareProductDataSerializer {
             if (product.setTotalIssuedShares(sharesIssued)) {
                 
actualChanges.put(ShareProductApiConstants.totalsharesissued_paramname, 
sharesIssued);
             }
+        }else {
+            product.setTotalIssuedShares(sharesIssued) ;
         }
-
+        
+        if(sharesIssued != null && product.getSubscribedShares() != null && 
sharesIssued < product.getSubscribedShares()) {
+            
baseDataValidator.reset().parameter(ShareProductApiConstants.totalsharesissued_paramname).value(sharesIssued)
+            
.failWithCodeNoParameterAddedToErrorCode("sharesissued.can.not.be.lessthan.accounts.subscribed.shares");
+        }
+        
+        
         if 
(this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.currency_paramname,
 element)
                 && 
this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.digitsafterdecimal_paramname,
 element)
                 && 
this.fromApiJsonHelper.parameterExists(ShareProductApiConstants.inmultiplesof_paramname,
 element)) {
@@ -416,17 +429,17 @@ public class ShareProductDataSerializer {
             }
         }
 
+        if (!dataValidationErrors.isEmpty()) { throw new 
PlatformApiDataValidationException(dataValidationErrors); }
+        
         BigDecimal shareCapitalValue;
         if (sharesIssued != null || unitPrice != null) {
-            if (sharesIssued == null) sharesIssued = product.getSharesIssued();
+            if (sharesIssued == null) sharesIssued = product.getTotalShares();
             if (unitPrice == null) unitPrice = product.getUnitPrice();
             shareCapitalValue = 
BigDecimal.valueOf(sharesIssued).multiply(unitPrice);
             if (product.setshareCapitalValue(shareCapitalValue)) {
                 
actualChanges.put(ShareProductApiConstants.sharecapital_paramname, 
shareCapitalValue);
             }
         }
-
-        if (!dataValidationErrors.isEmpty()) { throw new 
PlatformApiDataValidationException(dataValidationErrors); }
         return actualChanges;
     }
 
@@ -455,6 +468,7 @@ public class ShareProductDataSerializer {
                 ShareProductApiConstants.dividendAmountParamName, element);
         
baseDataValidator.reset().parameter(ShareProductApiConstants.dividendAmountParamName).value(dividendAmount).notBlank()
                 .positiveAmount();
+        if (!dataValidationErrors.isEmpty()) { throw new 
PlatformApiDataValidationException(dataValidationErrors); }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/60588a78/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java
index 1ff71c7..12ac51e 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductDividendAssembler.java
@@ -26,13 +26,14 @@ import java.util.Map;
 import org.apache.fineract.organisation.monetary.domain.MonetaryCurrency;
 import org.apache.fineract.organisation.monetary.domain.Money;
 import 
org.apache.fineract.portfolio.products.service.ProductReadPlatformService;
-import org.apache.fineract.portfolio.shareaccounts.data.PurchasedSharesData;
+import 
org.apache.fineract.portfolio.shareaccounts.data.ShareAccountTransactionData;
 import org.apache.fineract.portfolio.shareaccounts.data.ShareAccountData;
 import 
org.apache.fineract.portfolio.shareaccounts.domain.PurchasedSharesStatusType;
 import 
org.apache.fineract.portfolio.shareaccounts.domain.ShareAccountDividendDetails;
 import 
org.apache.fineract.portfolio.shareaccounts.service.ShareAccountReadPlatformService;
 import org.apache.fineract.portfolio.shareproducts.data.ShareProductData;
 import 
org.apache.fineract.portfolio.shareproducts.domain.ShareProductDividendPayOutDetails;
+import 
org.apache.fineract.portfolio.shareproducts.exception.ShareAccountsNotFoundException;
 import org.joda.time.Days;
 import org.joda.time.LocalDate;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -59,8 +60,15 @@ public class ShareProductDividendAssembler {
                 .getCurrency().currencyInMultiplesOf());
         Collection<ShareAccountData> shareAccountDatas = 
this.ShareAccountReadPlatformService.retrieveAllShareAccountDataForDividends(
                 productId, 
product.getAllowDividendCalculationForInactiveClients(), 
dividendPeriodStartDate);
+        if(shareAccountDatas == null || shareAccountDatas.isEmpty()) {
+            throw new ShareAccountsNotFoundException(product.getId()) ;
+        }
+        
         ShareProductDividendPayOutDetails productDividendPayOutDetails = null;
-        final int minimumActivePeriod = product.getMinimumActivePeriod();
+        int minimumActivePeriod = 0 ;
+        if(product.getMinimumActivePeriod() != null) { //minimum active period 
may be null 
+            minimumActivePeriod = product.getMinimumActivePeriod();
+        }
         final Map<Long, Long> numberOfSharesdaysPerAccount = new HashMap<>();
         long numberOfShareDays = 
calculateNumberOfShareDays(dividendPeriodEndDate, dividendPeriodStartDate, 
minimumActivePeriod,
                 shareAccountDatas, numberOfSharesdaysPerAccount);
@@ -88,10 +96,10 @@ public class ShareProductDividendAssembler {
         long numberOfShareDays = 0;
         for (ShareAccountData accountData : shareAccountDatas) {
             long numberOfShareDaysPerAccount = 0;
-            Collection<PurchasedSharesData> purchasedShares = 
accountData.getPurchasedShares();
+            Collection<ShareAccountTransactionData> purchasedShares = 
accountData.getPurchasedShares();
             long numberOfShares = 0;
             LocalDate lastDividendAppliedDate = null;
-            for (PurchasedSharesData purchasedSharesData : purchasedShares) {
+            for (ShareAccountTransactionData purchasedSharesData : 
purchasedShares) {
                 final PurchasedSharesStatusType status = 
PurchasedSharesStatusType.fromInt(purchasedSharesData.getStatus().getId()
                         .intValue());
                 final PurchasedSharesStatusType type = 
PurchasedSharesStatusType.fromInt(purchasedSharesData.getType().getId()

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/60588a78/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java
 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java
index cd3b42e..64dc94e 100644
--- 
a/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java
+++ 
b/fineract-provider/src/main/java/org/apache/fineract/portfolio/shareproducts/service/ShareProductReadPlatformServiceImpl.java
@@ -243,7 +243,7 @@ public class ShareProductReadPlatformServiceImpl implements 
ProductReadPlatformS
                     currencyDisplaySymbol, currencyNameCode);
 
             final Long totalShares = rs.getLong("total_shares");
-            final Long issuedShares = rs.getLong("issued_shares");
+            final Long issuedShares = 
JdbcSupport.getLongDefaultToNullIfZero(rs, "issued_shares");
             final BigDecimal unitPrice = rs.getBigDecimal("unit_price");
             final BigDecimal capitalAmount = 
rs.getBigDecimal("capital_amount");
             final Long minimumClientShares = JdbcSupport.getLong(rs, 
"minimum_client_shares");

http://git-wip-us.apache.org/repos/asf/incubator-fineract/blob/60588a78/fineract-provider/src/main/resources/sql/migrations/core_db/V299__share_products.sql
----------------------------------------------------------------------
diff --git 
a/fineract-provider/src/main/resources/sql/migrations/core_db/V299__share_products.sql
 
b/fineract-provider/src/main/resources/sql/migrations/core_db/V299__share_products.sql
index ec3a27c..509d167 100644
--- 
a/fineract-provider/src/main/resources/sql/migrations/core_db/V299__share_products.sql
+++ 
b/fineract-provider/src/main/resources/sql/migrations/core_db/V299__share_products.sql
@@ -129,16 +129,18 @@ CREATE TABLE `m_share_account_transactions` (
 `unit_price` DECIMAL(10,2) NULL DEFAULT NULL,
 `amount` DECIMAL(20,2) NULL DEFAULT NULL,
 `charge_amount` DECIMAL(20,2) NULL DEFAULT NULL,
+`amount_paid` DECIMAL(20,2) NULL DEFAULT NULL,
 `status_enum` SMALLINT(5) NOT NULL DEFAULT '300',
 `type_enum` SMALLINT(5) NULL DEFAULT NULL,
+`is_active` TINYINT(1) NOT NULL DEFAULT '1',
 PRIMARY KEY (`id`),
 CONSTRAINT `m_share_account_purchased_shares_ibfk_1` FOREIGN KEY 
(`account_id`) REFERENCES `m_share_account` (`id`)
 ) ;
 
 CREATE TABLE `m_share_account_charge_paid_by` (
 `id` BIGINT(20) NOT NULL AUTO_INCREMENT,
-`share_transaction_id` BIGINT(20) NOT NULL,
-`charge_transaction_id` BIGINT(20) NOT NULL,
+`share_transaction_id` BIGINT(20) NULL DEFAULT NULL,
+`charge_transaction_id` BIGINT(20) NULL DEFAULT NULL,
 `amount` DECIMAL(20,2) NOT NULL,
 PRIMARY KEY (`id`),
 CONSTRAINT `m_share_account_transactions_charge_mapping_ibfk1` FOREIGN KEY 
(`share_transaction_id`) REFERENCES `m_share_account_transactions` (`id`),

Reply via email to