Blame view

src/pages/Attendence/viewTeacherAttendence.vue 16.3 KB
0cd2fbfba   Neeraj Sharma   implement create ...
1
2
  <template>
    <v-container fluid grid-list-md>
159dff730   Neeraj Sharma   implement functio...
3
      <div v-show="hideData">
67a276510   Shikha Mishra   fixed all bugs
4
5
        <v-layout row>
          <v-btn @click="exportPdf" round class="right open-dialog-button" dark>
0cd2fbfba   Neeraj Sharma   implement create ...
6
7
8
            Export Pdf
            <v-icon dark right size="20">save_alt</v-icon>
          </v-btn>
db965de89   Amber Dev   added dialog pers...
9
          <v-dialog v-model="dialogExport" max-width="500px" persistent>
2fe1115d8   Shikha Mishra   added csv button ...
10
            <v-btn round slot="activator" class="right open-dialog-button" dark>
0cd2fbfba   Neeraj Sharma   implement create ...
11
12
              Export csv
              <v-icon dark right size="20">save_alt</v-icon>
2fe1115d8   Shikha Mishra   added csv button ...
13
            </v-btn>
67a276510   Shikha Mishra   fixed all bugs
14
            <v-card flat class="card-style pa-2" dark>
c9f61969a   Amber Dev   attendence download
15
              <h3 class="title text-xs-center">Export</h3>
0cd2fbfba   Neeraj Sharma   implement create ...
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
              <v-card-text>
                <v-container grid-list-md>
                  <v-layout wrap>
                    <v-flex xs12>
                      <v-menu
                        ref="menuStartDate"
                        :close-on-content-click="false"
                        v-model="menuStartDate"
                        :nudge-right="40"
                        :return-value.sync="startDate"
                        lazy
                        transition="scale-transition"
                        offset-y
                        full-width
                        min-width="290px"
                      >
                        <v-text-field
                          slot="activator"
                          v-model="startDate"
                          label="Select Start Date"
                          prepend-icon="event"
                          readonly
                        ></v-text-field>
                        <v-date-picker
                          v-model="startDate"
                          @input="$refs.menuStartDate.save(startDate)"
                        ></v-date-picker>
                      </v-menu>
                    </v-flex>
                    <v-flex xs12>
                      <v-menu
                        ref="menuEndDate"
                        :close-on-content-click="false"
                        v-model="menuEndDate"
                        :nudge-right="40"
                        :return-value.sync="endDate"
                        lazy
                        transition="scale-transition"
                        offset-y
                        full-width
                        min-width="290px"
                      >
                        <v-text-field
                          slot="activator"
                          v-model="endDate"
                          label="Select End Date"
                          prepend-icon="event"
                          readonly
                        ></v-text-field>
                        <v-date-picker v-model="endDate" @input="$refs.menuEndDate.save(endDate)"></v-date-picker>
                      </v-menu>
                    </v-flex>
                  </v-layout>
                </v-container>
              </v-card-text>
              <v-card-actions>
                <v-spacer></v-spacer>
c9f61969a   Amber Dev   attendence download
73
74
75
                <v-btn flat @click.native="dialogExport = false">Close</v-btn>
  
                <v-btn flat @click.native="exportData">Export</v-btn>
0cd2fbfba   Neeraj Sharma   implement create ...
76
77
78
              </v-card-actions>
            </v-card>
          </v-dialog>
67a276510   Shikha Mishra   fixed all bugs
79
        </v-layout>
0cd2fbfba   Neeraj Sharma   implement create ...
80
81
82
        <v-layout wrap>
          <v-flex xs12 sm12 md4>
            <v-card flat>
68d742034   Neeraj Sharma   implement new des...
83
              <h3 class="py-2 text-xs-center card-style white--text">Profile</h3>
0cd2fbfba   Neeraj Sharma   implement create ...
84
85
86
87
88
89
90
91
92
              <v-card-text>
                <v-container>
                  <v-layout wrap>
                    <v-flex xs12>
                      <v-layout>
                        <v-flex
                          xs12
                          class="text-xs-center text-sm-center text-md-center text-lg-center"
                        >
68d742034   Neeraj Sharma   implement new des...
93
                          <v-avatar size="80px">
159dff730   Neeraj Sharma   implement functio...
94
                            <img src="/static/icon/user.png" v-if="!teacherData.profilePicUrl" />
0cd2fbfba   Neeraj Sharma   implement create ...
95
                            <img
159dff730   Neeraj Sharma   implement functio...
96
97
                              :src="teacherData.profilePicUrl"
                              v-else-if="teacherData.profilePicUrl"
0cd2fbfba   Neeraj Sharma   implement create ...
98
99
100
101
102
103
104
                            />
                          </v-avatar>
                        </v-flex>
                      </v-layout>
                      <v-layout>
                        <v-flex xs12 sm12>
                          <h3 class="text-xs-center">
159dff730   Neeraj Sharma   implement functio...
105
                            <b>{{ teacherData.name }}</b>
0cd2fbfba   Neeraj Sharma   implement create ...
106
107
108
109
110
111
112
113
114
115
116
117
118
                          </h3>
                          <p class="text-xs-center grey--text">Teacher</p>
                        </v-flex>
                      </v-layout>
                      <!-- <v-layout style="border: 1px solid lightgrey;">
                        <v-flex xs6 sm6 class="pa-0">
                          <h4 class="right">
                            <b>Gender :</b>
                          </h4>
                        </v-flex>
                        <v-flex sm6 xs6 class="pa-0">
                          <h4>{{ teacherData.teacherData.gender }}</h4>
                        </v-flex>
159dff730   Neeraj Sharma   implement functio...
119
                      </v-layout>-->
0cd2fbfba   Neeraj Sharma   implement create ...
120
121
122
123
124
125
126
                      <v-layout style="border: 1px solid lightgrey;">
                        <v-flex xs6 sm6 class="pa-0">
                          <h4 class="right">
                            <b>D.O.B:</b>
                          </h4>
                        </v-flex>
                        <v-flex sm6 xs6 class="right pa-0">
159dff730   Neeraj Sharma   implement functio...
127
                          <h4>{{ dates(teacherData.dob) }}</h4>
0cd2fbfba   Neeraj Sharma   implement create ...
128
129
130
131
132
133
134
135
136
                        </v-flex>
                      </v-layout>
                      <v-layout style="border: 1px solid lightgrey;">
                        <v-flex xs6 sm6 class="right pa-0">
                          <h4 class="right">
                            <b>Phone :</b>
                          </h4>
                        </v-flex>
                        <v-flex sm6 xs6 class="right pa-0">
159dff730   Neeraj Sharma   implement functio...
137
                          <h4>{{ teacherData.mobileNo}}</h4>
0cd2fbfba   Neeraj Sharma   implement create ...
138
139
140
141
142
143
144
145
146
147
                        </v-flex>
                      </v-layout>
                    </v-flex>
                  </v-layout>
                </v-container>
              </v-card-text>
            </v-card>
          </v-flex>
          <v-flex xs12 sm12 md8>
            <v-card flat>
68d742034   Neeraj Sharma   implement new des...
148
              <h3 class="py-2 text-xs-center card-style white--text">
0cd2fbfba   Neeraj Sharma   implement create ...
149
150
151
152
153
154
155
156
157
158
                Attendence
                <span class="ml-4">
                  <v-avatar class="green caption" size="12"></v-avatar>
                  <span class="subheading">Present</span>
                </span>
                <span class="ml-4">
                  <v-avatar color="red caption" size="12" class></v-avatar>
                  <span class="subheading">Absent</span>
                </span>
              </h3>
159dff730   Neeraj Sharma   implement functio...
159
              <YearCalendar
0cd2fbfba   Neeraj Sharma   implement create ...
160
161
162
163
                v-model="year"
                :activeDates="activeDates"
                prefixClass="your_customized_wrapper_class"
                :activeClass="activeClass"
159dff730   Neeraj Sharma   implement functio...
164
              ></YearCalendar>
0cd2fbfba   Neeraj Sharma   implement create ...
165
166
167
168
169
170
171
            </v-card>
          </v-flex>
        </v-layout>
      </div>
      <v-layout v-show="showPdfData">
        <v-container>
          <v-flex xs12 sm12 md8 offset-sm2>
67a276510   Shikha Mishra   fixed all bugs
172
            <v-btn class="right add-button" @click="generatePDF2Canvas()" :loading="loadingPdf" dark>
0cd2fbfba   Neeraj Sharma   implement create ...
173
174
              Download
              <v-icon dark right size="20">save_alt</v-icon>
67a276510   Shikha Mishra   fixed all bugs
175
            </v-btn>
0cd2fbfba   Neeraj Sharma   implement create ...
176
177
178
179
180
181
182
183
184
          </v-flex>
        </v-container>
      </v-layout>
      <v-layout v-show="showPdfData">
        <v-container>
          <v-layout v-show="showPdfData">
            <v-flex xs12 sm12 md8 offset-sm2>
              <div ref="printMe">
                <v-flex xs12 class="pl-3">
67a276510   Shikha Mishra   fixed all bugs
185
                  <v-layout>
0cd2fbfba   Neeraj Sharma   implement create ...
186
187
188
189
190
191
                    <v-flex xs6 sm2 class="pa-0 mb-1">
                      <h4>
                        <b>Name</b>
                      </h4>
                    </v-flex>
                    <v-flex sm10 xs6 class="pa-0">
67a276510   Shikha Mishra   fixed all bugs
192
                      <h4>: {{ teacherData.name }}</h4>
0cd2fbfba   Neeraj Sharma   implement create ...
193
194
195
196
197
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs6 sm2 class="pa-0 mb-1">
                      <h4>
67a276510   Shikha Mishra   fixed all bugs
198
                        <b>Email</b>
0cd2fbfba   Neeraj Sharma   implement create ...
199
200
201
                      </h4>
                    </v-flex>
                    <v-flex sm10 xs6 class="pa-0 mb-1">
67a276510   Shikha Mishra   fixed all bugs
202
                      <h4>: {{ teacherData.email }}</h4>
0cd2fbfba   Neeraj Sharma   implement create ...
203
204
205
206
207
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs6 sm2 class="pa-0 mb-1">
                      <h4>
67a276510   Shikha Mishra   fixed all bugs
208
                        <b>City</b>
0cd2fbfba   Neeraj Sharma   implement create ...
209
210
                      </h4>
                    </v-flex>
67a276510   Shikha Mishra   fixed all bugs
211
212
                    <v-flex sm10 xs6 class="pa-0 mb-3">
                      <h4>: {{ teacherData.city}}</h4>
0cd2fbfba   Neeraj Sharma   implement create ...
213
214
215
216
217
                    </v-flex>
                  </v-layout>
                  <v-layout>
                    <v-flex xs6 sm2 class="pa-0 mb-1">
                      <h4>
67a276510   Shikha Mishra   fixed all bugs
218
                        <b>Mobile No</b>
0cd2fbfba   Neeraj Sharma   implement create ...
219
220
221
                      </h4>
                    </v-flex>
                    <v-flex sm10 xs6 class="pa-0 mb-3">
67a276510   Shikha Mishra   fixed all bugs
222
                      <h4>: {{ teacherData.mobileNo}}</h4>
0cd2fbfba   Neeraj Sharma   implement create ...
223
                    </v-flex>
67a276510   Shikha Mishra   fixed all bugs
224
                  </v-layout>
0cd2fbfba   Neeraj Sharma   implement create ...
225
                </v-flex>
67a276510   Shikha Mishra   fixed all bugs
226
                <v-card flat>
0cd2fbfba   Neeraj Sharma   implement create ...
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
                  <h3 class="py-2 text-xs-center grey lighten-1 white--text">
                    Attendence
                    <span class="ml-4">
                      <v-avatar class="green caption" size="12"></v-avatar>
                      <span class="subheading">Present</span>
                    </span>
                    <span class="ml-4">
                      <v-avatar color="red caption" size="12" class></v-avatar>
                      <span class="subheading">Absent</span>
                    </span>
                  </h3>
                  <YearCalendar
                    v-model="year"
                    :activeDates="activeDates"
                    prefixClass="your_customized_wrapper_class"
                    :activeClass="activeClass"
67a276510   Shikha Mishra   fixed all bugs
243
244
                  ></YearCalendar>
                </v-card>
0cd2fbfba   Neeraj Sharma   implement create ...
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
              </div>
            </v-flex>
          </v-layout>
        </v-container>
      </v-layout>
      <!-- <img :src="output" v-show="false"/> -->
      <div class="loader" v-if="showLoader">
        <v-progress-circular indeterminate color="white"></v-progress-circular>
      </div>
    </v-container>
  </template>
  
  <script lang="js">
  import moment from "moment";
  import http from "@/Services/http.js";
  import YearCalendar from "vue-material-year-calendar";
  import jsPDF from 'jspdf';
      // eslint-disable-next-line
  import autoTable from 'jspdf-autotable';
  
  export default {
    components: { YearCalendar },
    data() {
      return {
        showPdfData:false,
        hideData:true,
        loadingPdf:false,
        output:null,
        studentsList: [],
        json_data: [],
        dialogExport: false,
        startDate: "",
        endDate: "",
        menuEndDate: false,
        menuStartDate: false,
        showLoader: false,
        token: "",
        year: new Date().getFullYear(),
        activeDates: [],
        activeClass: "",
        teacherData: {}
      };
    },
    mounted() {
      this.token = this.$store.state.token;
      this.getTeacherAttendence();
      // this.getStudentData();
    },
    methods: {
      dates: function(date) {
        return moment(date).format("MMMM DD, YYYY");
      },
      getTeacherAttendence() {
        this.showLoader = true;
        http()
          .get(
            "/teacherAttendance",
            { params: { teacherId: this.$route.params.teacherId } },
            {
              headers: { Authorization: "Bearer " + this.token }
            }
          )
          .then(response => {
            this.showLoader = false;
159dff730   Neeraj Sharma   implement functio...
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
            this.teacherData = response.data.data.teacherData;
            let array = [];
            for (let i = 0; i < response.data.data.attendanceData.length; i++) {
            for (let j = 0; j < response.data.data.attendanceData[i].teachers.length; j++) {
                if (response.data.data.attendanceData[i].teachers[j].attendanceType === "present") {
                array.push({
                  date: response.data.data.attendanceData[i].date,
                  className: "green"
                });
              } else if (response.data.data.attendanceData[i].teachers[j].attendanceType === "latePresentWithExcuse") {
                array.push({
                  date: response.data.data.attendanceData[i].date,
                  className: "yellow"
                });
              }
               else if (response.data.data.attendanceData[i].teachers[j].attendanceType === "latePresent") {
                array.push({
                  date: response.data.data.attendanceData[i].date,
                  className: "black"
                });
              }
               else if (response.data.data.attendanceData[i].teachers[j].attendanceType === "absent") {
                array.push({
                  date: response.data.data.attendanceData[i].date,
                  className: "red"
                });
              }
            }
            this.activeDates = array;
            }            
0cd2fbfba   Neeraj Sharma   implement create ...
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
          })
          .catch(error => {
            this.showLoader = false;
            if (error.response.status === 401) {
              this.$router.replace({ path: "/" });
              this.$store.dispatch("setToken", null);
              this.$store.dispatch("Id", null);
              this.$store.dispatch("Role", null);
            }
          });
      },
  //     getStudentData() {
  //       http()
  //         .get(
  //           "/getParticularStudentDetail",
  //           { params: { studentId: this.$route.params.id } },
  //           {
  //             headers: { Authorization: "Bearer " + this.token }
  //           }
  //         )
  //         .then(response => {
  //           this.studentData = response.data.data;
  //         })
  //         .catch(err => {
  //           console.log("err====>", err);
  //           // this.$router.replace({ path: '/' });
  //         });
  //     },
c9f61969a   Amber Dev   attendence download
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
  convertToCSV(objArray) {
      var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
      var str = '';
  
      for (var i = 0; i < array.length; i++) {
          var line = '';
          for (var index in array[i]) {
              if (line != '') line += ','
  
              line += array[i][index];
          }
  
          str += line + '\r
  ';
      }
  
      return str;
      },
2fe1115d8   Shikha Mishra   added csv button ...
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
      exportData() {
          // console.log("id",this.$route.params.teacherId);
        http()
          .get(
            "/teacherAttendanceByMonth",
            {
              params: {
                teacherId: this.$route.params.teacherId,
                startDate: this.startDate,
                endDate: this.endDate
              }
            },
            {
              headers: { Authorization: "Bearer " + this.token }
            }
          )
          .then(response => {
            this.json_data = response.data.data;
            this.dialogExport = false;
c9f61969a   Amber Dev   attendence download
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
            var jsonObject = JSON.stringify(this.json_data);
            var csv = this.convertToCSV(jsonObject);
            var exportedFilenmae = "teacherAttendance" + '.csv';
            var blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
                  if (navigator.msSaveBlob) { // IE 10+
                navigator.msSaveBlob(blob, exportedFilenmae);
            } else {
                var link = document.createElement("a");
                if (link.download !== undefined) { // feature detection
                    // Browsers that support HTML5 download attribute
                    var url = URL.createObjectURL(blob);
                    link.setAttribute("href", url);
                    link.setAttribute("download", exportedFilenmae);
                    link.style.visibility = 'hidden';
                    document.body.appendChild(link);
                    link.click();
                    document.body.removeChild(link);
                }
            }
  
      
2fe1115d8   Shikha Mishra   added csv button ...
425
426
          })
          .catch(err => {
860da881d   Shikha Mishra   comment all consoles
427
428
429
430
  		//   console.log("err====>", err);
  			this.snackbar = true;
              this.color = "error";
              this.text = error.response.data.message;
2fe1115d8   Shikha Mishra   added csv button ...
431
432
433
            // this.$router.replace({ path: '/' });
          });
      },
67a276510   Shikha Mishra   fixed all bugs
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
      exportPdf(){
          this.hideData = false;
          this.showPdfData = true   
      },
       async  generatePDF2Canvas(){
              this.loadingPdf = true
              const el = this.$refs.printMe;
              // add option type to get the image version
              // if not provided the promise will return 
              // the canvas.
              const options = {
                  type: 'dataURL'
              }
              this.output = await this.$html2canvas(el, options);
              if(this.output) {
                 this.loadingPdf = false
              }
              let doc = new jsPDF();
              doc.addImage(this.output, 'JPEG', 5, 10, 200, 280);
              doc.save("Attendance.pdf");
          }
0cd2fbfba   Neeraj Sharma   implement create ...
455
456
457
    }
  };
  </script>
67a276510   Shikha Mishra   fixed all bugs
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
  <style scoped>
  .add-button {
    background: #feb83c !important;
    border-color: #feb83c !important;
    text-transform: none !important;
    -webkit-box-shadow: none !important;
    box-shadow: none !important;
  }
  .card-style {
    background: #7f62f8 !important;
    border-color: #7f62f8 !important;
    border-radius: 12px;
  }
  .open-dialog-button {
    background: #827bfa !important;
    border-color: #827bfa !important;
    text-transform: none !important;
  }
  </style>