Merge pull request #503 from ShruthiRajaram/FINERACT-680

FINERACT-680 market price update issue in share product
This commit is contained in:
ShruthiRajaram
2018-12-31 17:19:07 +05:30
committed by GitHub
@@ -20,6 +20,7 @@ package org.apache.fineract.portfolio.shareproducts.domain;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
@@ -48,6 +49,7 @@ import org.apache.fineract.portfolio.shareproducts.data.ShareProductMarketPriceD
import org.apache.fineract.useradministration.domain.AppUser; import org.apache.fineract.useradministration.domain.AppUser;
import org.joda.time.DateTime; import org.joda.time.DateTime;
@SuppressWarnings("serial")
@Entity @Entity
@Table(name = "m_share_product") @Table(name = "m_share_product")
public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> { public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
@@ -282,23 +284,26 @@ public class ShareProduct extends AbstractAuditableCustom<AppUser, Long> {
} }
public boolean setMarketPrice(Set<ShareProductMarketPriceData> marketPrice) { public boolean setMarketPrice(Set<ShareProductMarketPriceData> marketPrice) {
boolean update = false; boolean update = true;
for (ShareProductMarketPriceData data : marketPrice) { Set<ShareProductMarketPrice> marketPriceTemp = new HashSet<ShareProductMarketPrice>();
if (data.getId() == null) { if (marketPrice != null && marketPrice.size() > 0) {
ShareProductMarketPrice entity = new ShareProductMarketPrice(data.getStartDate(), data.getShareValue()); for (ShareProductMarketPriceData data : marketPrice) {
entity.setShareProduct(this); if (data.getId() == null) {
this.marketPrice.add(entity); ShareProductMarketPrice entity = new ShareProductMarketPrice(data.getStartDate(), data.getShareValue());
update = true; entity.setShareProduct(this);
} else { marketPriceTemp.add(entity);
for (ShareProductMarketPrice priceData : this.marketPrice) { } else {
if (priceData.getId() == data.getId()) { for (ShareProductMarketPrice priceData : this.marketPrice) {
priceData.setStartDate(data.getStartDate()); if (priceData.getId().equals(data.getId())) {
priceData.setShareValue(data.getShareValue()); priceData.setStartDate(data.getStartDate());
update = true; priceData.setShareValue(data.getShareValue());
} marketPriceTemp.add(priceData);
} }
} }
} }
}
}
this.marketPrice = marketPriceTemp;
return update; return update;
} }