Subversion Repositories SmartDukaan

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
32331 amit.gupta 1
<div class="col-lg-12">
2
    <table class="table table-border table-condensed table-bordered"
3
           id="circular-table">
4
 
5
        <thead>
6
            #set($rowspan = 1)
7
            #if($allMargins.size() > 0 || $offers.size() > 0)
8
                #set($rowspan=2)
9
            #end
10
 
11
        <tr>
12
            <th rowspan="$rowspan">Model Id</th>
13
            <th rowspan=$rowspan>Model</th>
14
            <th rowspan=$rowspan>Type</th>
15
            <th rowspan=$rowspan>MRP</th>
16
            <th rowspan=$rowspan>MOP</th>
17
            <th rowspan=$rowspan>DP</th>
18
            #if($sellins.size() > 0)
19
                <th colspan="$sellins.size()" style="text-align: center">Sell In</th>
20
            #end
21
            #if($sellouts.size() > 0)
22
                <th colspan="$sellouts.size()" style="text-align: center
23
                ">Sell Out
24
                </th>
25
            #end
26
            #set($add=0)
27
            #if($upgradeOffer)
28
                <th rowspan=$rowspan>Upgrade Offer</th>
29
                #set($add=1)
30
            #end
31
            #foreach($offer in $offers)
32
                #set($fieldIndex=$velocityCount*2 + (4 + $allMargins.size() + $add))
33
                <th data-idx="$fieldIndex" colspan=2 data-offerid="$offer.getId()"><a href="javascript:void(0)"
34
                                                                                      class="mk_partner_view">$offer.getName()</a>
35
                </th>
36
            #end
37
            <th rowspan=$rowspan>NLC</th>
38
            <th rowspan=$rowspan>MOP-DP</th>
39
            <th rowspan=$rowspan>Total Margin</th>
40
            <th rowspan=$rowspan>Net % Margin</th>
41
 
42
        </tr>
43
            #if($rowspan==2)
44
            <tr>
45
                #foreach($marginName in $allMargins)
46
                    <th>$marginName</th>
47
                #end
48
                #foreach($offer in $offers)
49
                    <th>Target</th>
50
                    <th>Margin</th>
51
                #end
52
            </tr>
53
            #end
54
        </thead>
55
        <tbody>
56
            #foreach($priceCircularItemModel in $priceCircularItemModels )
57
            <tr>
58
                <td>$priceCircularItemModel.getCatalogSummaryModel().getCatalogId()</td>
59
                <td>$priceCircularItemModel.getCatalogSummaryModel().getModelName() $priceCircularItemModel.getCatalogSummaryModel().getModelNumber()</td>
60
                <td>$priceCircularItemModel.getCatalogSummaryModel().getCategory()</td>
61
                <td class="currency">$priceCircularItemModel.getCatalogSummaryModel().getMrp()</td>
62
                <td class="currency mop"
63
                    data-value="$priceCircularItemModel.getCatalogSummaryModel().getMop()">$priceCircularItemModel.getCatalogSummaryModel().getMop()</td>
64
                <td class="currency dp"
65
                    data-value='$priceCircularItemModel.getCatalogSummaryModel().getDp()'>$priceCircularItemModel.getCatalogSummaryModel().getDp()</td>
66
                #foreach($marginName in $allMargins)
67
                    #if ($priceCircularItemModel.getHeaderSchemeModelsMap().containsKey($marginName))
68
                        <td class="currency margin"
69
                            data-value='$mvcResponseSender.createResponseString($priceCircularItemModel.getHeaderSchemeModelsMap().get($marginName))'>$mvcResponseSender.createResponseString($priceCircularItemModel.getHeaderSchemeModelsMap().get($marginName))</td>
70
                    #else
71
                        <td>-</td>
72
                    #end
73
                #end
74
                #if($upgradeOffer)
75
                    <td class="currency">$priceCircularItemModel.getUpgradeOffer()</td>
76
                #end
77
                #foreach($slabPayouts in $priceCircularItemModel.getSlabPayouts())
78
                    #if($slabPayouts && $slabPayouts.size()>0)
79
                        <td>
80
                            <select class="mk_criteria_slab"
81
                                    data-value='$slabPayouts.entrySet().iterator().next().getValue()'>
82
                                #foreach($payout in $slabPayouts.entrySet())
83
                                    <option value='$mvcResponseSender.createResponseString($payout.getValue())'>$payout.getKey()
84
                                        onwards
85
                                    </option>
86
                                #end
87
                            </select>
88
                        </td>
89
                        <td class="currency margin"
90
                            data-value='$mvcResponseSender.createResponseString($slabPayouts.values().iterator().next())'>
91
                            $mvcResponseSender.createResponseString($slabPayouts.values().iterator().next())
92
                        </td>
93
                    #else
94
                        <td> -</td>
95
                        <td> -</td>
96
                    #end
97
                #end
98
                <td class="currency netprice">-</td>
99
                <td class="currency dpmop">-</td>
100
                <td class="currency totalmargin">-</td>
101
                <td class="netmargin">-</td>
102
 
103
            </tr>
104
            #end
105
        </tbody>
106
    </table>
107
</div>
108
 
109
<div class="offer-margin-container">
110
    <div class="modal  text-center" id="offerDescription">
111
        <div class="modal-dialog modal-lg modal-dialog-scrollable">
112
            <div class="modal-content">
113
            </div>
114
        </div>
115
    </div>
116
</div>
117
<script type="text/javascript">
118
    $(document).ready(function () {
119
        $('#circular-table').find('tr').each(function (i, el) {
120
            setMargins(el);
121
        });
122
        #if($priceCircularItemModels.size()>5)
123
            priceCircularTable = $('#circular-table').DataTable({
124
                "scrollX": true,
125
                "bPaginate": true,
126
                "bLengthChange": true,
127
                "bFilter": true,
128
                "bInfo": false,
129
                "bAutoWidth": false,
130
                "pageLength": 100,
131
                lengthMenu: [
132
                    [100, -1],
133
                    [100, 'All'],
134
                ]
135
            });
136
        #end
137
        //setMargins();
138
    });
139
 
140
    $('select.mk_criteria_slab').change(function () {
141
        let tdPayout = $(this).closest('td').next();
142
        tdPayout.data("value", JSON.parse($(this).val()));
143
        console.log("--------" + tdPayout.data('value'));
144
        setMargins($(this).closest('tr'));
145
        priceCircularTable.draw();
146
    });
147
 
148
    function setMargins(trContainer) {
149
        let dp = $(trContainer).find('.dp').data("value");
150
        if (dp == undefined) return;
151
        let mop = $(trContainer).find('.mop').data('value');
152
        let totalMargin = 0;
153
        if ($(trContainer).find('.margin').length > 0) {
154
            let fixedMargin = 0;
155
            let percentageMargin = 0;
156
            $(trContainer).find('.margin').each(function (i, ele) {
157
                let amountModel = $(ele).data('value');
158
                //console.log(amountModel);
159
                if (amountModel.amountType == 'FIXED') {
160
                    if (!amountModel.discount)
161
                        fixedMargin += amountModel.amount;
162
                } else if (amountModel.amountType == 'PERCENTAGE') {
163
                    percentageMargin += amountModel.amount;
164
                }
165
            });
166
            let effectiveDp = dp - fixedMargin;
167
            console.log(fixedMargin);
168
            let percentageValue = effectiveDp / (100 + percentageMargin);
169
            console.log(percentageValue + "(" + percentageMargin + "%)");
170
            $(trContainer).find('.margin').each(function (i, ele) {
171
                let amountModel = $(ele).data('value');
172
                //console.log(amountModel);
173
                if (amountModel.amountType == 'PERCENTAGE') {
174
                    $(ele).html(numberToComma(percentageValue * amountModel.amount));
175
                    totalMargin += percentageValue * amountModel.amount;
176
                } else {
177
                    $(ele).html(numberToComma(amountModel.amount));
178
                    totalMargin += amountModel.amount;
179
                }
180
            });
181
        }
182
        let dpmop = mop - dp;
183
        let nlc = dp - totalMargin;
184
        $(trContainer).find('.netprice').html(numberToComma(nlc));
185
        $(trContainer).find('.dpmop').html(numberToComma(dpmop));
186
        totalMargin += dpmop;
187
        $(trContainer).find('.totalmargin').html(numberToComma(totalMargin));
188
        //debugger;
189
        $(trContainer).find('.netmargin').html(numberToComma(totalMargin * 100 / (nlc)) + '%');
190
        //priceCircularTable.draw();
191
    }
192
 
193
</script>