package io.github.zutherb.appstash.shop.service.order.model;

import io.github.zutherb.appstash.shop.service.user.model.UserInfo;
import io.github.zutherb.appstash.shop.service.user.model.UserInfo;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

/**
 * @author zutherb
 */
public class OrderInfo implements Serializable {

    private Long orderId;
    private UserInfo user;
    private List<OrderItemInfo> orderItems;
    private DeliveryAddressInfo deliveryAddress;
    private Date orderDate;
    private String sessionId;

    private OrderInfo() {
    }

    public OrderInfo(UserInfo user, DeliveryAddressInfo deliveryAddress, List<OrderItemInfo> orderItems, String sessionId) {
        this.user = user;
        this.orderItems = orderItems;
        this.deliveryAddress = deliveryAddress;
        this.sessionId = sessionId;
    }

    public OrderInfo(Long orderId, String sessionId, OrderInfo orderInfo) {
        this.orderId = orderId;
        this.sessionId = sessionId;
        this.user = orderInfo.getUser();
        this.orderItems = orderInfo.getOrderItems();
        this.deliveryAddress = orderInfo.getDeliveryAddress();
    }

    public OrderInfo(Long orderId, OrderInfo orderInfo, List<OrderItemInfo> orderItemInfos, String sessionId) {
        this(orderId, sessionId, orderInfo);
        this.orderItems = orderItemInfos;
        this.sessionId = sessionId;
    }

    public String getSessionId() {
        return sessionId;
    }

    public UserInfo getUser() {
        return user;
    }

    public void setUser(UserInfo user) {
        this.user = user;
    }

    public List<OrderItemInfo> getOrderItems() {
        if (orderItems == null) {
            orderItems = new ArrayList<>();
        }
        return Collections.unmodifiableList(orderItems);
    }

    public DeliveryAddressInfo getDeliveryAddress() {
        return deliveryAddress;
    }

    public BigDecimal getDiscountSum() {
        BigDecimal totalSum = BigDecimal.ZERO;
        for (OrderItemInfo orderItemInfo : orderItems) {
            totalSum = totalSum.add(orderItemInfo.getTotalSum());
        }
        double discountPercent = 25/100;
        BigDecimal decimalDiscountPercent = new BigDecimal(Double.toString(discountPercent));
        BigDecimal discountAmount = totalSum.multiply(decimalDiscountPercent);
        discountAmount = discountAmount.setScale(2, RoundingMode.HALF_UP);
        return discountAmount;
    }

    public BigDecimal getTotalSum() {
        BigDecimal totalSum = BigDecimal.ZERO;
        for (OrderItemInfo orderItemInfo : orderItems) {
            totalSum = totalSum.add(orderItemInfo.getTotalSum());
        }
        // double fraction = 25/100;        
        // return totalSum.subtract(totalSum.multiply(new BigDecimal(fraction)));
        
        return totalSum;
    }
    
    
    public Long getOrderId() {
        return orderId;
    }

    public Date getOrderDate() {
        return orderDate;
    }
}

@@ -2263,31 +2263,22 @@
  double 
-discountPercent
+factor
  = 25/10
@@ -2278,16 +2278,18 @@
 = 25/100
+.0
 ;%0A      
@@ -2294,277 +2294,94 @@
     
-BigDecimal decimalDiscountPercent = new BigDecimal(Double.toString(discountPercent));%0A        BigDecimal discountAmount = totalSum.multiply(decimalDiscountPercent);%0A        discountAmount = discountAmount.setScale(2, RoundingMode.HALF_UP);%0A        return discountAmount
+double result = totalSum.doubleValue() * factor;%0A        return new BigDecimal(result)
 ;%0A  

Update OrderInfo.java