Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
34055 ranu 1
package com.spice.profitmandi.dao.model;
2
 
3
import javax.persistence.*;
4
import java.util.Objects;
5
 
6
 
7
@Entity
8
@NamedNativeQueries({
9
        @NamedNativeQuery(name = "Aging.SoldAgingModel",
10
                query = "SELECT" +
11
                        "       a.Rbm_Name," +
12
                        "       SUM(CASE WHEN cc.status = 'EOL' THEN tl.selling_price ELSE 0 END) AS EOL_Billed," +
13
                        "       SUM(CASE  WHEN cc.status = 'SLOWMOVING' THEN tl.selling_price  ELSE 0 END) AS Slowmoving_Billed," +
14
                        "       SUM(CASE WHEN cc.status = 'FASTMOVING' THEN tl.selling_price  ELSE 0 END)  AS Fastmoving_Billed," +
15
                        "       SUM(CASE WHEN cc.status = 'HID' THEN tl.selling_price ELSE 0 END) AS HID_Billed," +
16
                        "       SUM(CASE WHEN cc.status IS NULL THEN tl.selling_price ELSE 0 END) AS Other_Billed," +
17
                        "       SUM(tl.selling_price) AS Total_Amount" +
18
                        " FROM (SELECT au.id                                    AS auth_id," +
19
                        "             CONCAT(au.first_name, ' ', au.last_name) AS Rbm_Name," +
20
                        "             fs.id                                    AS fofo_id" +
21
                        "      FROM auth.auth_user au" +
22
                        "               JOIN cs.position p ON p.auth_user_id = au.id" +
23
                        "               JOIN cs.partner_position pp ON pp.position_id = p.id" +
24
                        "               JOIN fofo.fofo_store fs ON fs.id = pp.partner_id" +
25
                        "      WHERE pp.partner_id != 0" +
26
                        "        AND p.category_id = 18" +
27
                        "        AND p.escalation_type = 'L1'" +
28
                        "        AND fs.active = 1" +
29
                        "        and fs.internal = false" +
30
                        "      UNION ALL" +
31
                        "      SELECT au.id                                    AS auth_id," +
32
                        "             CONCAT(au.first_name, ' ', au.last_name) AS Rbm_Name," +
33
                        "             fs.id                                    AS fofo_id" +
34
                        "      FROM auth.auth_user au" +
35
                        "               JOIN cs.position p ON p.auth_user_id = au.id" +
36
                        "               JOIN cs.partner_position pp ON pp.position_id = p.id" +
37
                        "               JOIN cs.region r ON pp.region_id = r.id" +
38
                        "               JOIN cs.partner_region pr ON pr.region_id = pp.region_id" +
39
                        "               JOIN fofo.fofo_store fs ON fs.id = pr.fofo_id" +
40
                        "      WHERE pp.partner_id = 0" +
41
                        "        AND p.category_id = 18" +
42
                        "        AND fs.active = 1" +
43
                        "        and fs.internal = false" +
44
                        "        AND p.escalation_type = 'L1') a" +
45
                        "      JOIN transaction.order o on (o.customer_id = a.fofo_id)" +
46
                        "      JOIN transaction.lineitem li ON li.order_id = o.id AND li.brand NOT IN ('Smartdukaan', 'Dummy', 'FOC', 'Live Demo')" +
47
                        "      JOIN catalog.item ci ON ci.id = li.item_id" +
48
                        "      JOIN catalog.tag_listing tl ON tl.item_id = ci.id" +
49
                        "      JOIN catalog.catagoriesd_catalog cc ON cc.catalog_id = ci.catalog_item_id" +
50
                        "      AND (cc.start_date <= o.created_timestamp AND  (cc.end_date IS NULL OR cc.end_date > o.created_timestamp))" +
51
                        "      JOIN warehouse.scanNew s ON s.orderId = o.id" +
52
                        "      JOIN warehouse.inventoryItem ii ON ii.id = s.inventoryItemId" +
53
                        "      JOIN warehouse.inventoryItem ii2 ON ii.serialNumber = ii2.serialNumber AND ii2.lastScanType != 'PURCHASE_RETURN'" +
54
                        "      JOIN warehouse.purchase p ON p.id = ii2.purchaseId" +
55
                        "      JOIN warehouse.purchaseorder po ON po.id = p.purchaseOrder_id" +
34068 ranu 56
                        "      JOIN warehouse.invoice inv ON p.invoice_id = inv.id AND po.supplierId = inv.supplierId AND po.warehouseId = ii2.physicalWarehouseId" +
34055 ranu 57
                        "      JOIN warehouse.supplier su ON su.id = inv.supplierId AND su.internal = 0" +
58
                        "" +
34056 ranu 59
                        " where ((o.created_timestamp >= :startDate AND o.created_timestamp < :endDate) AND (o.billing_timestamp >= :startDate AND o.billing_timestamp < :endDate) AND o.refund_timestamp IS NULL)" +
34055 ranu 60
                        " and DATEDIFF(NOW(), inv.invoiceDate) > 15" +
61
                        " GROUP BY a.auth_id, a.Rbm_Name",
62
                resultSetMapping = "SoldAgingModel"),
63
 
64
})
65
 
66
@SqlResultSetMappings({
67
 
68
        @SqlResultSetMapping(name = "SoldAgingModel",
69
                classes = {@ConstructorResult(targetClass = Sold15daysOldAgingModel.class,
70
                        columns = {
71
                                @ColumnResult(name = "Rbm_Name", type = String.class),
72
                                @ColumnResult(name = "EOL_Billed ", type = Long.class),
73
                                @ColumnResult(name = "Slowmoving_Billed ", type = Long.class),
74
                                @ColumnResult(name = "Fastmoving_Billed ", type = Long.class),
75
                                @ColumnResult(name = "HID_Billed ", type = Long.class),
76
                                @ColumnResult(name = "Other_Billed ", type = Long.class),
77
                                @ColumnResult(name = "Total_Amount ", type = Long.class),
78
                        }
79
                )}
80
        )
81
 
82
})
83
 
84
public class Sold15daysOldAgingModel {
85
    String rbmName;
86
    long eolBilled;
87
    long runningBilled;
88
    long fastmovingBilled;
89
    long hidBilled;
90
    long othersBilled;
91
    long totalBilled;
92
 
93
    // Synthetic primary key to satisfy JPA's requirement
94
    @Id
95
    @GeneratedValue(strategy = GenerationType.IDENTITY)
96
    private Long id; // This will not be used in the query but satisfies JPA.
97
 
98
    public Sold15daysOldAgingModel(String rbmName, long eolBilled, long runningBilled, long fastmovingBilled, long hidBilled, long othersBilled, long totalBilled) {
99
        this.rbmName = rbmName;
100
        this.eolBilled = eolBilled;
101
        this.runningBilled = runningBilled;
102
        this.fastmovingBilled = fastmovingBilled;
103
        this.hidBilled = hidBilled;
104
        this.othersBilled = othersBilled;
105
        this.totalBilled = totalBilled;
106
    }
107
 
108
    public String getRbmName() {
109
        return rbmName;
110
    }
111
 
112
    public void setRbmName(String rbmName) {
113
        this.rbmName = rbmName;
114
    }
115
 
116
    public long getEolBilled() {
117
        return eolBilled;
118
    }
119
 
120
    public void setEolBilled(long eolBilled) {
121
        this.eolBilled = eolBilled;
122
    }
123
 
124
    public long getRunningBilled() {
125
        return runningBilled;
126
    }
127
 
128
    public void setRunningBilled(long runningBilled) {
129
        this.runningBilled = runningBilled;
130
    }
131
 
132
    public long getFastmovingBilled() {
133
        return fastmovingBilled;
134
    }
135
 
136
    public void setFastmovingBilled(long fastmovingBilled) {
137
        this.fastmovingBilled = fastmovingBilled;
138
    }
139
 
140
    public long getHidBilled() {
141
        return hidBilled;
142
    }
143
 
144
    public void setHidBilled(long hidBilled) {
145
        this.hidBilled = hidBilled;
146
    }
147
 
148
    public long getOthersBilled() {
149
        return othersBilled;
150
    }
151
 
152
    public void setOthersBilled(long othersBilled) {
153
        this.othersBilled = othersBilled;
154
    }
155
 
156
    public long getTotalBilled() {
157
        return totalBilled;
158
    }
159
 
160
    public void setTotalBilled(long totalBilled) {
161
        this.totalBilled = totalBilled;
162
    }
163
 
164
    @Override
165
    public String toString() {
166
        return "Sold15daysAgingModel{" +
167
                "rbmName='" + rbmName + '\'' +
168
                ", eolBilled=" + eolBilled +
169
                ", runningBilled=" + runningBilled +
170
                ", fastmovingBilled=" + fastmovingBilled +
171
                ", hidBilled=" + hidBilled +
172
                ", othersBilled=" + othersBilled +
173
                ", totalBilled=" + totalBilled +
174
                '}';
175
    }
176
 
177
    @Override
178
    public boolean equals(Object o) {
179
        if (this == o) return true;
180
        if (o == null || getClass() != o.getClass()) return false;
181
        Sold15daysOldAgingModel that = (Sold15daysOldAgingModel) o;
182
        return eolBilled == that.eolBilled && runningBilled == that.runningBilled && fastmovingBilled == that.fastmovingBilled && hidBilled == that.hidBilled && othersBilled == that.othersBilled && totalBilled == that.totalBilled && Objects.equals(rbmName, that.rbmName);
183
    }
184
 
185
    @Override
186
    public int hashCode() {
187
        return Objects.hash(rbmName, eolBilled, runningBilled, fastmovingBilled, hidBilled, othersBilled, totalBilled);
188
    }
189
}