Subversion Repositories SmartDukaan

Rev

Rev 34527 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
34527 tejus.loha 1
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
31001 amit.gupta 2
 
34527 tejus.loha 3
 
4
<!-- Chart.js Datalabels plugin for v2 -->
5
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@0.7.0"></script>
6
 
7
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4"></script>
8
 
9
 
33501 ranu 10
<div>
31001 amit.gupta 11
 
12
 
34527 tejus.loha 13
 
31001 amit.gupta 14
    <div class="row">
34527 tejus.loha 15
        <div class="col-lg-7">
16
            <h4><strong>Investometer</strong></h4>
17
            <canvas id="investometerGauge"></canvas>
18
        </div>
31001 amit.gupta 19
 
34527 tejus.loha 20
 
21
        <div class="col-lg-5">
35396 amit 22
            <h4 style="margin-bottom:24px "><strong>Banner for Shopfront</strong></h4>
33501 ranu 23
            <div class="form-group">
33504 ranu 24
                #if(!$printResources.isEmpty())
34527 tejus.loha 25
                    <div id="myCarousel" class="carousel slide" data-ride="carousel" style="margin-top: 50px">
33504 ranu 26
                        <!-- Wrapper for slides -->
27
                        <div class="carousel-inner text-center">
33501 ranu 28
                            #set($first = true)
29
                            #foreach($printResource in $printResources)
30
                                <div class="item #if($first)active#set($first = false)#end">
31
                                    <img src="$printResource.getThumbnailUrl()" alt="Los Angeles"
32
                                         style="max-height:150px;width:auto;max-width: 100%;margin: auto;">
33
                                    <div class="carousel-caption">
34
                                        <br>
33502 ranu 35
                                        <button class="btn btn-danger btn-sm partner_print_resources">Get File !
36
                                        </button>
33501 ranu 37
                                    </div>
38
                                </div>
34527 tejus.loha 39
 
33501 ranu 40
                            #end
33504 ranu 41
                        </div>
42
                        <!-- Left and right controls -->
43
                        <a class="left carousel-control" href="#myCarousel" data-slide="prev">
44
                            <span class="glyphicon glyphicon-chevron-left"></span>
45
                            <span class="sr-only">Previous</span>
46
                        </a>
47
                        <a class="right carousel-control" href="#myCarousel" data-slide="next">
48
                            <span class="glyphicon glyphicon-chevron-right"></span>
49
                            <span class="sr-only">Next</span>
50
                        </a>
33501 ranu 51
                    </div>
33504 ranu 52
                #end
53
                #if($printResources.isEmpty())
54
                    <div class="form-group">
55
                        <img src="/resources/images/image-not-found.png"
56
                             style="max-height:150px;width:auto;max-width: 100%;margin: auto;">
57
                    </div>
58
                #end
33501 ranu 59
            </div>
31001 amit.gupta 60
        </div>
61
    </div>
62
 
63
</div>
64
<script>
34527 tejus.loha 65
 
66
    function formatIndianNumber(number) {
67
        return Number(number).toLocaleString('en-IN');
31001 amit.gupta 68
    }
34527 tejus.loha 69
 
70
    (function () {
71
        const isInvestmentOk = $investments.get('isInvestmentOk');
72
        const partnerType = "$investments.get('partnerType')";
73
        let cutOfPercent =  $investments.get('cutOf');
74
        let minimumInvestmentParcent =  $investments.get('minInvestment');
75
 
76
        let agreedInvestment =$investments.get('minimumInvestment');
77
        let currentInvestment =$investments.get('totalInvestment');
35396 amit 78
        let billBlockPercentAmt = ((agreedInvestment * cutOfPercent) / 100).toFixed(2);
79
        let maintainPercentAmt = ((agreedInvestment * minimumInvestmentParcent) / 100).toFixed(2);
34527 tejus.loha 80
 
35396 amit 81
        var percentForNeedle = 0.00;
34527 tejus.loha 82
 
35396 amit 83
        if (currentInvestment > agreedInvestment) {
34527 tejus.loha 84
            percentForNeedle = 98;
35396 amit 85
        } else {
34527 tejus.loha 86
            percentForNeedle = ((currentInvestment / agreedInvestment) * 100).toFixed(2)
87
        }
88
        const percent = ((currentInvestment / agreedInvestment) * 100).toFixed(2);
35396 amit 89
        console.log("percentForNeedle - ", percentForNeedle)
90
        console.log("percent - ", percent)
34527 tejus.loha 91
 
92
 
35396 amit 93
        let billBlockPercentAmtFormmated = formatIndianNumber(billBlockPercentAmt);
94
        let agreedInvestmentFormmated = formatIndianNumber(agreedInvestment);
95
        let currentInvestmentFormmated = formatIndianNumber(currentInvestment);
96
        let maintainPercentAmtFormmated = formatIndianNumber(maintainPercentAmt);
34527 tejus.loha 97
        const ctx = document.getElementById("investometerGauge").getContext("2d");
98
        let labels = [];
99
        let data = [];
100
        let colors = [];
101
 
102
        if (isInvestmentOk) {
35396 amit 103
            if (partnerType == "BRONZE") {
34527 tejus.loha 104
                // One segments: Investment OK bcoz of Partner type BRONZE
105
                labels = [
106
                    `Investment OK (${currentInvestmentFormmated})+`
107
                ];
108
                data = [100];
109
                colors = ["green"];
35396 amit 110
            } else {
34527 tejus.loha 111
                // Three segments: Billing Blocked, Increase Investment, Investment OK
112
                labels = [
113
                    `70% of Agreed Investment(Billing Block)  (${billBlockPercentAmtFormmated})`,
114
                    `75% of Agreed Investment(Increase Investment) (${maintainPercentAmtFormmated})`,
115
                    `Investment OK (${maintainPercentAmtFormmated})+`
116
                ];
117
                data = [70, 5, 25];
118
                colors = ["red", "orange", "green"];
119
            }
120
 
121
 
122
        } else {
123
            // Only two segments: Billing Blocked and Investment OK
124
            labels = [
125
                `75% of Agreed Investment(Billing Block)  (${billBlockPercentAmtFormmated})`,
126
                `Investment OK (${maintainPercentAmtFormmated})+`
127
            ];
128
            data = [75, 25];
129
            colors = ["red", "green"];
130
        }
131
        const gaugeChart = new Chart(ctx, {
132
            type: 'doughnut',
133
            data: {
134
                labels: labels,
135
                datasets: [{
136
                    data: data,
137
                    backgroundColor: colors,
138
                    borderWidth: 2
139
                }]
140
 
141
            },
142
            options: {
143
                responsive: true,
144
                cutoutPercentage: 20,
145
                rotation: -Math.PI,
146
                circumference: Math.PI,
147
                title: {
148
                    display: true,
149
                    text: `Current Invested Value: Rs.${currentInvestment.toLocaleString('en-IN')}(${percent}%)`
150
                },
35396 amit 151
                tooltips: {enabled: true},
34527 tejus.loha 152
                animation: {
153
                    animateRotate: true,
154
                    animateScale: false
155
                },
156
                plugins: {
157
                    datalabels: {
158
                        display: true,
159
                        formatter: (value, context) => context.chart.data.labels[context.dataIndex],
160
                    }
161
                }
162
            },
163
            plugins: [{
164
                // Draw needle after the chart renders
165
                afterDraw: function (chart) {
166
                    const needleValue = percentForNeedle;
167
                    const total = chart.config.data.datasets[0].data.reduce((a, b) => a + b, 0);
168
                    const angle = Math.PI + (Math.PI * needleValue / total);
169
                    const ctx = chart.chart.ctx;
170
                    const cw = chart.chartArea;
171
                    const cx = (cw.left + cw.right) / 2;
172
                    const cy = chart.chartArea.bottom;
173
                    const needleLength = chart.outerRadius * 0.9;
174
                    const needleRadius = 8;
175
 
176
                    // Clear needle
177
                    ctx.save();
178
 
179
                    // Draw needle
180
                    ctx.translate(cx, cy);
181
                    ctx.rotate(angle);
182
                    ctx.beginPath();
183
                    ctx.moveTo(0, -needleRadius);
184
                    ctx.lineTo(needleLength, 0);
185
                    ctx.lineTo(0, needleRadius);
186
                    ctx.fillStyle = 'black';
187
                    ctx.fill();
188
 
189
                    // Draw needle dot
190
                    ctx.beginPath();
191
                    ctx.arc(0, 0, needleRadius, 0, Math.PI * 2);
192
                    ctx.fill();
193
 
194
                    ctx.restore();
195
                },
196
                datalabels: {
197
                    display: true,
35396 amit 198
                    formatter: function (value, context) {
34527 tejus.loha 199
                        const label = context.chart.data.labels[context.dataIndex];
200
 
201
                        if (label.includes("Billing Block")) {
202
                            return `₹${currentInvestment.toLocaleString('en-IN')}`;
203
                        }
204
                        if (label.includes("Investment OK")) {
205
                            return `₹${agreedInvestment.toLocaleString('en-IN')}`;
206
                        }
207
                        return label;
208
                    },
209
                    color: 'white',
210
                    font: {
211
                        weight: 'bold'
212
                    }
213
                }
214
            }]
215
        });
216
    })();
31001 amit.gupta 217
</script>
34527 tejus.loha 218
##<script type="text/javascript" src="resources/js/gauge.min.js"></script>