index.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import React, { Component } from "react";
  2. import ContentWrapper from "@/components/Layout/ContentWrapper";
  3. import { Row, Col } from "reactstrap";
  4. import { getPelaporan } from "@/actions/pelaporan";
  5. import { getGraph, getExcel, getlaporanselesai } from "@/actions/graph";
  6. import CaseProgress from "@/components/PelaporanTuntas/CaseProgress";
  7. import TableLaporan from "@/components/PelaporanTuntas/TableLaporan";
  8. import { connect } from "react-redux";
  9. import Loader from "@/components/Common/Loader";
  10. import Link from "next/link";
  11. import Button from "reactstrap/lib/Button";
  12. import Router from "next/router";
  13. import swal from "sweetalert2";
  14. class PelaporanTuntas extends Component {
  15. constructor(props) {
  16. super(props);
  17. this.state = {
  18. pelaporan: {},
  19. graph: {},
  20. tahun: new Date().getFullYear(),
  21. laporanSelesai: {}
  22. };
  23. }
  24. componentDidMount = async () => {
  25. const { token } = this.props;
  26. let laporanSelesai = await getlaporanselesai(token);
  27. laporanSelesai = {
  28. ...laporanSelesai, data: {
  29. ...laporanSelesai.data, laporan: [...laporanSelesai.data.laporan, ...laporanSelesai.data.sanksi], sanksi: null
  30. }
  31. }
  32. const pelaporan = await getPelaporan(token, { jadwal: true, aktif: false });
  33. const graph = await getGraph(this.props.token, { evaluasi: true, listJadwal: true, aktif: false });
  34. this.setState({ pelaporan, graph, laporanSelesai });
  35. };
  36. nextButton = async () => {
  37. const tahun = this.state.tahun + 1;
  38. const { token } = this.props;
  39. let laporanSelesai = await getlaporanselesai(token);
  40. laporanSelesai = {
  41. ...laporanSelesai, data: {
  42. ...laporanSelesai.data, laporan: [...laporanSelesai.data.laporan, ...laporanSelesai.data.sanksi], sanksi: null
  43. }
  44. }
  45. this.setState({ laporanSelesai, tahun });
  46. };
  47. prevButton = async () => {
  48. const tahun = this.state.tahun - 1;
  49. const { token } = this.props;
  50. let laporanSelesai = await getlaporanselesai(token);
  51. laporanSelesai = {
  52. ...laporanSelesai, data: {
  53. ...laporanSelesai.data, laporan: [...laporanSelesai.data.laporan, ...laporanSelesai.data.sanksi], sanksi: null
  54. }
  55. }
  56. this.setState({ laporanSelesai, tahun });
  57. };
  58. shouldComponentUpdate = (prevProps, prevState) => {
  59. if (prevState.graph !== this.state.graph) return true;
  60. };
  61. excel = () => {
  62. const url = getExcel(this.props.token, "Laporan", { tahun: this.state.tahun });
  63. Router.push(url);
  64. };
  65. excelMenu = () => {
  66. if (this.props?.user?.role.id === 2024) {
  67. swal.fire({
  68. icon: 'error',
  69. title: 'Oops...',
  70. html: 'Maaf anda tidak memiliki akses untuk menyelesaikan<p> proses ini.</p>',
  71. confirmButtonColor: "#3e3a8e",
  72. confirmButtonText: 'Oke'
  73. })
  74. } else {
  75. const url = getExcel(this.props.token, "Laporan", {
  76. tahun: this.state.tahun,
  77. pelaporan: true,
  78. });
  79. if (this.state.graph.data.jumlah_ditutup && this.state.graph.data.jumlah_selesai) {
  80. Router.push(url);
  81. } else {
  82. swal.fire({
  83. title: "Data Kosong",
  84. icon: "error",
  85. confirmButtonColor: "#3e3a8e",
  86. });
  87. }
  88. }
  89. };
  90. excelSemua = () => {
  91. if (this.props?.user?.role.id === 2024) {
  92. swal.fire({
  93. icon: 'error',
  94. title: 'Oops...',
  95. html: 'Maaf anda tidak memiliki akses untuk menyelesaikan<p> proses ini.</p>',
  96. confirmButtonColor: "#3e3a8e",
  97. confirmButtonText: 'Oke'
  98. })
  99. } else {
  100. const url = getExcel(this.props.token, "Laporan", {
  101. tahun: this.state.tahun,
  102. pelaporan: true,
  103. penjadwalan: true,
  104. pemeriksaan: true,
  105. sanksi: true,
  106. });
  107. if (this.state.graph.data.jumlah_ditutup && this.state.graph.data.jumlah_selesai) {
  108. Router.push(url);
  109. } else {
  110. swal.fire({
  111. title: "Data Kosong",
  112. icon: "error",
  113. confirmButtonColor: "#3e3a8e",
  114. });
  115. }
  116. }
  117. };
  118. render() {
  119. const { pelaporan, graph, laporanSelesai } = this.state;
  120. return (
  121. <ContentWrapper>
  122. <div className="content-heading">
  123. <span className="font-color-white">
  124. Pelaporan Tuntas
  125. </span>
  126. </div>
  127. <Row>
  128. <Col lg="4">{laporanSelesai?.data ? <CaseProgress data={laporanSelesai.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} excel={this.excel} excelMenu={this.excelMenu} excelSemua={this.excelSemua} /> : <Loader />}</Col>
  129. <Col lg="8">{laporanSelesai?.data?.laporan ? <TableLaporan status noBy listData={laporanSelesai.data.laporan} to="/app/tuntas/detail" linkName="Detail" /> : <Loader />}</Col>
  130. </Row>
  131. </ContentWrapper>
  132. );
  133. }
  134. }
  135. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  136. export default connect(mapStateToProps)(PelaporanTuntas);