index.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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, { tuntas: true });
  33. const graph = await getGraph(this.props.token, { evaluasi: true, listJadwal: true, aktif: false });
  34. this.setState({ pelaporan, graph, laporanSelesai });
  35. console.log(this.state.pelaporan)
  36. };
  37. nextButton = async () => {
  38. const tahun = this.state.tahun + 1;
  39. const { token } = this.props;
  40. let laporanSelesai = await getlaporanselesai(token);
  41. laporanSelesai = {
  42. ...laporanSelesai, data: {
  43. ...laporanSelesai.data, laporan: [...laporanSelesai.data.laporan, ...laporanSelesai.data.sanksi], sanksi: null
  44. }
  45. }
  46. this.setState({ laporanSelesai, tahun });
  47. };
  48. prevButton = async () => {
  49. const tahun = this.state.tahun - 1;
  50. const { token } = this.props;
  51. let laporanSelesai = await getlaporanselesai(token);
  52. laporanSelesai = {
  53. ...laporanSelesai, data: {
  54. ...laporanSelesai.data, laporan: [...laporanSelesai.data.laporan, ...laporanSelesai.data.sanksi], sanksi: null
  55. }
  56. }
  57. this.setState({ laporanSelesai, tahun });
  58. };
  59. shouldComponentUpdate = (prevProps, prevState) => {
  60. if (prevState.graph !== this.state.graph) return true;
  61. };
  62. excel = () => {
  63. const url = getExcel(this.props.token, "Laporan", { tahun: this.state.tahun });
  64. Router.push(url);
  65. };
  66. excelMenu = () => {
  67. if (this.props?.user?.role.id === 2071) {
  68. swal.fire({
  69. icon: 'error',
  70. title: 'Oops...',
  71. html: 'Maaf anda tidak memiliki akses untuk menyelesaikan<p> proses ini.</p>',
  72. confirmButtonColor: "#3e3a8e",
  73. confirmButtonText: 'Oke'
  74. })
  75. } else {
  76. const url = getExcel(this.props.token, "Laporan", {
  77. tahun: this.state.tahun,
  78. pelaporan: true,
  79. });
  80. if (this.state.laporanSelesai.data.jumlah_ditutup && this.state.laporanSelesai.data.jumlah_selesai) {
  81. Router.push(url);
  82. } else {
  83. swal.fire({
  84. title: "Data Kosong",
  85. icon: "error",
  86. confirmButtonColor: "#3e3a8e",
  87. });
  88. }
  89. }
  90. };
  91. excelSemua = () => {
  92. if (this.props?.user?.role.id === 2071) {
  93. swal.fire({
  94. icon: 'error',
  95. title: 'Oops...',
  96. html: 'Maaf anda tidak memiliki akses untuk menyelesaikan<p> proses ini.</p>',
  97. confirmButtonColor: "#3e3a8e",
  98. confirmButtonText: 'Oke'
  99. })
  100. } else {
  101. const url = getExcel(this.props.token, "Laporan", {
  102. tahun: this.state.tahun,
  103. pelaporan: true,
  104. penjadwalan: true,
  105. pemeriksaan: true,
  106. sanksi: true,
  107. });
  108. if (this.state.laporanSelesai.data.jumlah_ditutup && this.state.laporanSelesai.data.jumlah_selesai) {
  109. Router.push(url);
  110. } else {
  111. swal.fire({
  112. title: "Data Kosong",
  113. icon: "error",
  114. confirmButtonColor: "#3e3a8e",
  115. });
  116. }
  117. }
  118. };
  119. render() {
  120. const { pelaporan, graph, laporanSelesai } = this.state;
  121. console.log(pelaporan)
  122. return (
  123. <ContentWrapper>
  124. <div className="content-heading">
  125. <span className="font-color-white">
  126. Pelaporan Tuntas
  127. </span>
  128. </div>
  129. <Row>
  130. <Col lg="4">{laporanSelesai?.data ? <CaseProgress user={this?.props?.user} data={laporanSelesai.data} nextButton={this.nextButton} prevButton={this.prevButton} tahun={this.state.tahun} excel={this.excel} excelMenu={this.excelMenu} excelSemua={this.excelSemua} /> : <Loader />}</Col>
  131. <Col lg="8">{laporanSelesai?.data?.laporan ? <TableLaporan status noBy listData={pelaporan.data} to="/app/tuntas/detail" linkName="Detail" /> : <Loader />}</Col>
  132. </Row>
  133. </ContentWrapper>
  134. );
  135. }
  136. }
  137. const mapStateToProps = (state) => ({ user: state.user, token: state.token });
  138. export default connect(mapStateToProps)(PelaporanTuntas);