Subversion Repositories SmartDukaan

Rev

Rev 33917 | Rev 33939 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33917 Rev 33920
Line 8... Line 8...
8
 
8
 
9
        @NamedNativeQuery(name = "RbmTarget.getRbmAchievedMonthlyTarget",
9
        @NamedNativeQuery(name = "RbmTarget.getRbmAchievedMonthlyTarget",
10
                query = "SELECT a.auth_id," +
10
                query = "SELECT a.auth_id," +
11
                        "       a.first_name," +
11
                        "       a.first_name," +
12
                        "       a.warehouse_id," +
12
                        "       a.warehouse_id," +
-
 
13
                        "     sum(b.total_billed)," +
13
                        "       ROUND(" +
14
                        "       ROUND(" +
14
                        "                   COALESCE(SUM(b.total_billed), 0)" +
15
                        "                   COALESCE(SUM(b.total_billed), 0)" +
15
                        "                   - COALESCE(SUM(ro.refundAmount), 0)" +
16
                        "                   - COALESCE(SUM(ro.refundAmount), 0)" +
16
                        "                   - COALESCE(SUM(b.total_rto_refund), 0), 0" +
17
                        "                   - COALESCE(SUM(b.total_rto_refund), 0), 0" +
17
                        "           ) AS target_achieved" +
18
                        "           ) AS target_achieved" +
Line 25... Line 26...
25
                        "                  JOIN cs.position p ON p.auth_user_id = au.id" +
26
                        "                  JOIN cs.position p ON p.auth_user_id = au.id" +
26
                        "                  JOIN cs.partner_position pp ON pp.position_id = p.id" +
27
                        "                  JOIN cs.partner_position pp ON pp.position_id = p.id" +
27
                        "                  JOIN fofo.fofo_store fs ON fs.id = pp.partner_id" +
28
                        "                  JOIN fofo.fofo_store fs ON fs.id = pp.partner_id" +
28
                        "         WHERE pp.partner_id != 0" +
29
                        "         WHERE pp.partner_id != 0" +
29
                        "           AND p.category_id = 18" +
30
                        "           AND p.category_id = 18" +
30
                        "           AND p.escalation_type = 'L1' AND fs.target != 0 group by warehouse_id, au.id" +
31
                        "           AND p.escalation_type = 'L1' AND fs.target != 0" +
31
                        "" +
32
                        "" +
32
                        "         UNION ALL" +
33
                        "         UNION ALL" +
33
                        "" +
34
                        "" +
34
                        "         SELECT au.id AS auth_id," +
35
                        "         SELECT au.id AS auth_id," +
35
                        "                au.first_name," +
36
                        "                au.first_name," +
Line 42... Line 43...
42
                        "                  JOIN cs.region r ON pp.region_id = r.id" +
43
                        "                  JOIN cs.region r ON pp.region_id = r.id" +
43
                        "                  JOIN cs.partner_region pr ON pr.region_id = pp.region_id" +
44
                        "                  JOIN cs.partner_region pr ON pr.region_id = pp.region_id" +
44
                        "                  JOIN fofo.fofo_store fs ON fs.id = pr.fofo_id" +
45
                        "                  JOIN fofo.fofo_store fs ON fs.id = pr.fofo_id" +
45
                        "         WHERE pp.partner_id = 0" +
46
                        "         WHERE pp.partner_id = 0" +
46
                        "           AND p.category_id = 18" +
47
                        "           AND p.category_id = 18" +
47
                        "           AND p.escalation_type = 'L1' AND fs.target != 0 group by au.id, warehouse_id" +
48
                        "           AND p.escalation_type = 'L1' AND fs.target != 0" +
48
                        "     ) a" +
49
                        "     ) a" +
49
                        "         LEFT JOIN (" +
50
                        "         LEFT JOIN (" +
50
                        "    SELECT fs.id AS CustomerID," +
51
                        "    SELECT odr.customer_id," +
51
                        "           fs.warehouse_id," +
-
 
52
                        "           odr.id," +
52
                        "           odr.id," +
53
                        "           SUM(CASE WHEN odr.billing_timestamp IS NOT NULL THEN odr.total_amount ELSE 0 END) AS total_billed," +
53
                        "           SUM(CASE WHEN odr.billing_timestamp IS NOT NULL THEN odr.total_amount ELSE 0 END) AS total_billed," +
54
                        "           SUM(CASE WHEN odr.refund_timestamp IS NOT NULL THEN odr.total_amount ELSE 0 END) AS total_rto_refund" +
54
                        "           SUM(CASE WHEN odr.refund_timestamp IS NOT NULL THEN odr.total_amount ELSE 0 END) AS total_rto_refund" +
55
                        "    FROM transaction.order odr" +
55
                        "    FROM transaction.order odr" +
56
                        "             JOIN fofo.fofo_store fs ON fs.id = odr.customer_id" +
-
 
57
                        "    JOIN transaction.lineitem li on li.order_id=odr.id" +
56
                        "    JOIN transaction.lineitem li on li.order_id=odr.id" +
58
                        "    JOIN catalog.item ci on ci.id=li.item_id" +
57
                        "    JOIN catalog.item ci on ci.id=li.item_id" +
59
                        "        where ci.category=10006" +
58
                        "        where ci.category=10006" +
60
                        "          and fs.target !=0" +
-
 
61
                        "      AND (" +
59
                        "      AND (" +
62
                        "            (odr.billing_timestamp >= :startDate AND odr.billing_timestamp < :endDate AND odr.refund_timestamp IS NULL)" +
60
                        "            (odr.billing_timestamp >= :startDate AND odr.billing_timestamp < :endDate AND odr.refund_timestamp IS NULL)" +
63
                        "            OR (odr.status = 31 AND odr.refund_timestamp >= :startDate AND odr.refund_timestamp < :endDate AND odr.billing_timestamp IS NOT NULL)" +
61
                        "            OR (odr.status = 31 AND odr.refund_timestamp >= :startDate AND odr.refund_timestamp < :endDate AND odr.billing_timestamp IS NOT NULL)" +
64
                        "        )" +
62
                        "        )" +
65
                        "    GROUP BY fs.warehouse_id, fs.id" +
63
                        "    GROUP BY odr.customer_id" +
66
                        ") b ON a.fofo_id = b.CustomerID AND a.warehouse_id = b.warehouse_id" +
64
                        ") b ON a.fofo_id = b.customer_id" +
67
                        "         LEFT JOIN transaction.returnorderinfo ro ON ro.orderId = b.id" +
65
                        "         LEFT JOIN transaction.returnorderinfo ro ON ro.orderId = b.id" +
-
 
66
                        "" +
68
                        " GROUP BY a.auth_id, a.first_name, a.warehouse_id",
67
                        " GROUP BY a.auth_id, a.warehouse_id",
69
                resultSetMapping = "AchievedMonthlyTarget"),
68
                resultSetMapping = "AchievedMonthlyTarget"),
70
 
69
 
71
})
70
})
72
 
71
 
73
@SqlResultSetMappings({
72
@SqlResultSetMappings({