Subversion Repositories SmartDukaan

Rev

Rev 31914 | Rev 31988 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
31903 amit.gupta 1
package com.spice.profitmandi.service.scheme;
2
 
3
import com.spice.profitmandi.dao.entity.fofo.OfferPayout;
4
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
31920 amit.gupta 5
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
6
import com.spice.profitmandi.dao.model.AmountModel;
31903 amit.gupta 7
 
8
import java.util.List;
9
import java.util.Objects;
10
import java.util.stream.Collectors;
11
 
12
public class InventoryPayoutModel {
13
    int inventoryItemId;
14
    List<SchemeInOut> schemePayouts;
15
    List<OfferPayout> offerPayouts;
16
 
17
    private double fixedAmount;
18
    private double percentageAmount;
19
    private double paidAmount;
31914 amit.gupta 20
    private double dp;
31903 amit.gupta 21
 
22
 
31920 amit.gupta 23
    public double getRolloutAmount(AmountModel amountModel) {
24
        double rollout = 0;
25
        if (amountModel.getAmountType().equals(AmountType.PERCENTAGE)) {
26
            double effectiveDp = this.getDp() - this.getFixedAmount();
27
            double totalPercentage = this.getPercentageAmount() + amountModel.getAmount();
28
            rollout = effectiveDp * (totalPercentage / (100 + totalPercentage) - (this.getPercentageAmount() / (100 + this.getPercentageAmount())));
29
        } else {
30
            rollout = amountModel.getAmount() * (100 / (100 + this.getPercentageAmount()));
31
        }
32
        return rollout;
33
    }
34
 
31903 amit.gupta 35
    public InventoryPayoutModel(int inventoryItemId, List<SchemeInOut> schemePayouts, List<OfferPayout> offerPayouts) {
36
        this.inventoryItemId = inventoryItemId;
37
        this.schemePayouts = schemePayouts;
38
        this.offerPayouts = offerPayouts;
39
    }
40
 
41
    @Override
42
    public String toString() {
43
        return "InventoryPayoutModel{" +
44
                "inventoryItemId=" + inventoryItemId +
45
                ", schemePayouts=" + schemePayouts +
46
                ", offerPayouts=" + offerPayouts +
47
                ", fixedAmount=" + fixedAmount +
48
                ", percentageAmount=" + percentageAmount +
49
                ", paidAmount=" + paidAmount +
50
                '}';
51
    }
52
 
53
    public double getPercentageAmount() {
54
        return percentageAmount;
55
    }
56
 
57
    public void setPercentageAmount(double percentageAmount) {
58
        this.percentageAmount = percentageAmount;
59
    }
60
 
61
    public double getPaidAmount() {
62
        double paidAmount = 0;
63
        return schemePayouts.stream().collect(Collectors.summingDouble(x -> x.getAmount())) + offerPayouts.stream().collect(Collectors.summingDouble(x -> x.getAmount()));
64
    }
65
 
66
    public void setPaidAmount(double paidAmount) {
67
        this.paidAmount = paidAmount;
68
    }
69
 
70
    public double getFixedAmount() {
71
        return 0;
72
        //return schemePayouts.stream().filter(x->x.get)
73
    }
74
 
75
    public void setFixedAmount(double fixedAmount) {
76
        this.fixedAmount = fixedAmount;
77
    }
78
 
79
    public int getInventoryItemId() {
80
        return inventoryItemId;
81
    }
82
 
83
    public void setInventoryItemId(int inventoryItemId) {
84
        this.inventoryItemId = inventoryItemId;
85
    }
86
 
87
    public List<SchemeInOut> getSchemePayouts() {
88
        return schemePayouts;
89
    }
90
 
91
    public void setSchemePayouts(List<SchemeInOut> schemePayouts) {
92
        this.schemePayouts = schemePayouts;
93
    }
94
 
95
    public List<OfferPayout> getOfferPayouts() {
96
        return offerPayouts;
97
    }
98
 
31914 amit.gupta 99
    public double getDp() {
100
        return dp;
101
    }
102
 
103
    public void setDp(double dp) {
104
        this.dp = dp;
105
    }
106
 
107
    @Override
108
    public boolean equals(Object o) {
109
        if (this == o) return true;
110
        if (o == null || getClass() != o.getClass()) return false;
111
        InventoryPayoutModel that = (InventoryPayoutModel) o;
112
        return inventoryItemId == that.inventoryItemId && Double.compare(that.fixedAmount, fixedAmount) == 0 && Double.compare(that.percentageAmount, percentageAmount) == 0 && Double.compare(that.paidAmount, paidAmount) == 0 && Double.compare(that.dp, dp) == 0 && Objects.equals(schemePayouts, that.schemePayouts) && Objects.equals(offerPayouts, that.offerPayouts);
113
    }
114
 
115
    @Override
116
    public int hashCode() {
117
        return Objects.hash(inventoryItemId, schemePayouts, offerPayouts, fixedAmount, percentageAmount, paidAmount, dp);
118
    }
119
 
31903 amit.gupta 120
    public void setOfferPayouts(List<OfferPayout> offerPayouts) {
121
        this.offerPayouts = offerPayouts;
122
    }
123
}