Sam1D

PfpdPencarian

May 26th, 2020
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from "react";
  2. import axios from "axios";
  3. import "devextreme/dist/css/dx.common.css";
  4. import { connect } from "react-redux";
  5. import pfpdbrowsefake from "./pfpdbrowsefake";
  6. import { HashRouter as Router, withRouter, Link } from "react-router-dom";
  7. import DataGrid, {
  8.   Column,
  9.   FilterRow,
  10.   ColumnChooser,
  11.   Pager,
  12.   Paging,
  13.   Export,
  14.   HeaderFilter,
  15. } from "devextreme-react/data-grid";
  16.  
  17. import {
  18.   Card,
  19.   Row,
  20.   Spin,
  21.   Button,
  22.   Icon,
  23.   Breadcrumb,
  24.   Menu,
  25.   Dropdown,
  26.   Drawer,
  27.   Tabs,
  28.   Alert,
  29. } from "antd";
  30.  
  31. import _ from "lodash";
  32. import moment from "moment";
  33.  
  34. import { setLogin } from "../../../appRedux/reducers/auth";
  35.  
  36. import {
  37.   setInput,
  38.   resetInput,
  39.   setMultiInput,
  40. } from "../../../appRedux/reducers/core";
  41.  
  42. import {
  43.   getBrowsePFPD,
  44.   getDokumenPabeanPFPD,
  45.   getDokumenPabeanDashboardPFPD,
  46.   getMaxSeriBarangPFPD,
  47.   getCekPeriksaMerahPFPD,
  48.   getListBarangPFPD,
  49.   getListDokapPFPD,
  50.   getListBarangPFPD2,
  51.   getNPDPFPD,
  52.   getReferensiDokumen,
  53.   setLoading,
  54.   resetDokumenPabeanFPD,
  55.   resetSave,
  56. } from "../../../appRedux/reducers/pfpd";
  57.  
  58. import { tgl } from "../../../appRedux/constant_list";
  59.  
  60. import ReactTable from "react-table";
  61.  
  62. import { getDokumen } from "../../../appRedux/reducers/dokumen";
  63.  
  64. import "react-table/react-table.css";
  65.  
  66. import StickyToolRight from "../../../components/StickyToolRight";
  67.  
  68. import IdentitasPerusahaan from "../PfpdDataHeader/IdentitasPerusahaan";
  69.  
  70. let timeout; // Timeout
  71.  
  72. const menu = (
  73.   <Menu>
  74.     <Menu.Item>
  75.       <a target="_blank" rel="noopener noreferrer">
  76.         Today
  77.       </a>
  78.     </Menu.Item>
  79.     <Menu.Item>
  80.       <a target="_blank" rel="noopener noreferrer">
  81.         Yesterday
  82.       </a>
  83.     </Menu.Item>
  84.     <Menu.Item>
  85.       <a target="_blank" rel="noopener noreferrer">
  86.         Last 7 Days
  87.       </a>
  88.     </Menu.Item>
  89.     <Menu.Item>
  90.       <a target="_blank" rel="noopener noreferrer">
  91.         Last 30 Days
  92.       </a>
  93.     </Menu.Item>
  94.     <Menu.Item>
  95.       <a target="_blank" rel="noopener noreferrer">
  96.         This Month
  97.       </a>
  98.     </Menu.Item>
  99.     <Menu.Item>
  100.       <a target="_blank" rel="noopener noreferrer">
  101.         Last Month
  102.       </a>
  103.     </Menu.Item>
  104.   </Menu>
  105. );
  106.  
  107. const { TabPane } = Tabs;
  108.  
  109. class PfpdPencarian extends React.Component {
  110.   constructor() {
  111.     super();
  112.  
  113.     this.state = {
  114.       formLayout: "",
  115.       current: "",
  116.       date: "",
  117.       data: [],
  118.       isLoad: false,
  119.       sidebarLeft: false,
  120.       click: 0,
  121.       clickedOnce: false,
  122.       showRedirect: false,
  123.     };
  124.   }
  125.  
  126.   componentDidMount() {
  127.     const a = this.props.getNPDPFPD(this.props.input.idHeader);
  128.     // this.props.resetDokumenPabeanFPD()
  129.     this.getDataBrowse();
  130.     this.props.resetSave();
  131.     // this.props.getBrowsePFPD()
  132.     console.log("bb", a);
  133.     this.props.resetInput();
  134.     if (
  135.       localStorage.getItem("Data") != null &&
  136.       localStorage.getItem("Data2") != null
  137.     ) {
  138.       localStorage.removeItem("Data");
  139.       localStorage.removeItem("Data2");
  140.     } else if (localStorage.getItem("Data2") != null) {
  141.       localStorage.removeItem("Data2");
  142.     } else {
  143.       console.log("no");
  144.     }
  145.   }
  146.  
  147.   componentDidUpdate(prevState) {
  148.     if (prevState.sidebarLeft !== this.state.sidebarLeft) {
  149.       if (this.state.sidebarLeft === true) {
  150.         timeout = setTimeout(() => {
  151.           console.log("[debug] @componentDidUpdate TRUE");
  152.         }, 3000);
  153.       } else if (this.state.sidebarLeft === false) {
  154.         clearTimeout(timeout);
  155.         console.log("[debug] @componentDidUpdate FALSE");
  156.       }
  157.     }
  158.   }
  159.  
  160.   onSelectionChanged = (data) => {
  161.     // this.props.history.push("pfpd-data-header");
  162.     console.log("Dua Kali");
  163.     this.props.resetInput();
  164.     this.onClick(data.data);
  165.   };
  166.  
  167.   onClick = (data) => {
  168.     console.log("dua kali");
  169.     console.log(data);
  170.     var idHeader = data.idHeader;
  171.     console.log("cc", idHeader);
  172.     try {
  173.       var newinput = {
  174.         idHeader: data.idHeader,
  175.         kodeJalur: data.kodeJalur,
  176.         nomorDaftar: data.nomorDaftar,
  177.         kodeDokumen: data.kodeDokumen,
  178.         tanggalDaftar: moment(data.tanggalDaftar, "DD-MM-YYYY"),
  179.       };
  180.     } catch (e) {
  181.       console.log(e);
  182.     }
  183.     this.props.setMultiInput(newinput);
  184.     this.props.getListDokapPFPD(idHeader);
  185.     this.props.getDokumenPabeanPFPD(idHeader);
  186.     this.props.history.push("pfpd-data-header");
  187.   };
  188.  
  189.   onCheck = (data) => {
  190.     // this.state.clickedOnce = undefined;
  191.     setTimeout(() => {
  192.       this.setState({
  193.         showRedirect: true,
  194.         click: 0,
  195.         isLoad: false,
  196.       });
  197.     }, 5000);
  198.     console.log("single click");
  199.     console.log(data);
  200.     var idHeader = data.idHeader;
  201.     console.log("cc", idHeader);
  202.     try {
  203.       var newinput = {
  204.         idHeader: data.idHeader,
  205.         kodeJalur: data.kodeJalur,
  206.         kodeDokumen: data.kodeDokumen,
  207.         nomorDaftar: data.nomorDaftar,
  208.         tanggalDaftar: moment(data.tanggalDaftar, "DD-MM-YYYY"),
  209.       };
  210.     } catch (e) {
  211.       console.log(e);
  212.     }
  213.     this.props.setMultiInput(newinput);
  214.     this.props.getListDokapPFPD(idHeader);
  215.     this.props.getDokumenPabeanPFPD(idHeader);
  216.   };
  217.   onOptionChanged = (e) => {
  218.     switch (e.fullName) {
  219.       case "columns[1].filterValue":
  220.         this.props.setInput("kodeDokumen", e.value);
  221.         break;
  222.  
  223.       case "columns[2].filterValue":
  224.         this.props.setInput("nomorAju", e.value);
  225.         break;
  226.  
  227.       case "columns[3].filterValue":
  228.         this.props.setInput("nomorDaftar", e.value);
  229.         break;
  230.  
  231.       case "columns[4].filterValue":
  232.         this.props.setInput("tanggalDaftar", e.value);
  233.         break;
  234.  
  235.       case "columns[5].filterValue":
  236.         this.props.setInput("namaEntitasUsaha", e.value);
  237.         break;
  238.  
  239.       case "columns[6].filterValue":
  240.         this.props.setInput("namaEntitasPpjk", e.value);
  241.         break;
  242.  
  243.       case "columns[7].filterValue":
  244.         this.props.setInput("umur", e.value);
  245.         break;
  246.  
  247.       case "columns[8].filterValue":
  248.         this.props.setInput("kodeJalur", e.value);
  249.         break;
  250.  
  251.       case "columns[9].filterValue":
  252.         this.props.setInput("status", e.value);
  253.         break;
  254.  
  255.       default:
  256.         break;
  257.     }
  258.  
  259.     console.log(e);
  260.  
  261.     this.getDataBrowse();
  262.   };
  263.   triggers = (data) => {
  264.     // let a = {...this.state.click}
  265.     this.setState({
  266.       click: this.state.click + 1,
  267.     });
  268.     console.log("sekali", this.state.click);
  269.     let timer = 100;
  270.     if (this.state.click == "1") {
  271.       setTimeout(() => {
  272.         this.setState({
  273.           isLoad: true,
  274.         });
  275.       }, timer);
  276.       setTimeout(() => {
  277.         this.props.resetInput();
  278.         this.onCheck(data.data);
  279.         this.setState({
  280.           sidebarLeft: true,
  281.         });
  282.       }, 250);
  283.     } else if (this.state.click == "2") {
  284.       this.setState({
  285.         isLoad: true,
  286.       });
  287.  
  288.       console.log("Dua Kali");
  289.       this.props.resetInput();
  290.       this.onClick(data.data);
  291.     }
  292.   };
  293.  
  294.   onClose = () => {
  295.     // this.props.resetInput()
  296.     this.setState({
  297.       sidebarLeft: false,
  298.     });
  299.     // this.props.history.push("pfpd-data-header");
  300.   };
  301.   onRedirect = () => {
  302.     this.props.history.push("pfpd-data-header");
  303.   };
  304.   getDataBrowse = () => {
  305.     // const nip = this.props.nip
  306.     const nipData = "198912242010121002";
  307.     // const nipData = "196908161996032002"
  308.     // const kodeKantor = this.props.kodeKantor
  309.     // const kodeKantor ="160200"
  310.     const kodeKantor = "040300";
  311.     //!TestingSKA
  312.     // https://api.beacukai.go.id/Pfpd/pemeriksaan-dokumen/browse/?operatorUmur=%3E&nip=196908161996032002&kodeKantor=160200
  313.     //!Testing BC2.0
  314.     //!Testing FTZ5
  315.     this.setState({
  316.       isLoad: true,
  317.     });
  318.     axios({
  319.       method: "GET",
  320.       url:
  321.         process.env.REACT_APP_PFPD +
  322.         "/pemeriksaan-dokumen/browse/?operatorUmur=>&page=0&nip=" +
  323.         nipData +
  324.         "&size=20&kodeKantor=" +
  325.         kodeKantor,
  326.  
  327.       headers: {
  328.         "beacukai-api-key": process.env.REACT_APP_SECRET_KEY_PFPD,
  329.       },
  330.     })
  331.       .then((res) => {
  332.         let resn = res.data;
  333.         console.log("res", res);
  334.         this.setState({
  335.           data: resn,
  336.           isLoad: false,
  337.         });
  338.       })
  339.       .catch((err) => {
  340.         this.setState({
  341.           isLoad: false,
  342.         });
  343.         console.log(err);
  344.       });
  345.   };
  346.   handleReset = () => {
  347.     this.props.resetInput();
  348.   };
  349.  
  350.   render() {
  351.     let newData = this.state.data.data;
  352.     // console.log('[debug] data', this.state.sidebarLeft);
  353.  
  354.     let bc = this.props.nip;
  355.     console.log("nip?", bc);
  356.     let kodeKantor = this.props.kodeKantor;
  357.     console.log("kk", kodeKantor);
  358.     const renderGridCell = (data) => {
  359.       console.log("apa", data.data.kodeJalur);
  360.       let warna = data.data.kodeJalur;
  361.       if (warna === "K") {
  362.         return (
  363.           <div
  364.             style={{
  365.               width: 40,
  366.               height: 20,
  367.               backgroundColor: "yellow",
  368.               color: "black",
  369.               textAlign: "center",
  370.               margin: "auto",
  371.             }}
  372.           >
  373.             {warna}
  374.           </div>
  375.         );
  376.       } else if (warna === "H") {
  377.         return (
  378.           <div
  379.             style={{
  380.               margin: "auto",
  381.               width: 40,
  382.               height: 20,
  383.               backgroundColor: "green",
  384.               color: "white",
  385.               textAlign: "center",
  386.             }}
  387.           >
  388.             {warna}
  389.           </div>
  390.         );
  391.       } else if (warna === "M") {
  392.         return (
  393.           <div
  394.             style={{
  395.               margin: "auto",
  396.               width: 40,
  397.               height: 20,
  398.               backgroundColor: "red",
  399.               color: "white",
  400.               textAlign: "center",
  401.             }}
  402.           >
  403.             {warna}
  404.           </div>
  405.         );
  406.       }
  407.     };
  408.     //console.log(this.props.pfpd)
  409.     // console.log('data', this.data.idHeader)
  410.     return (
  411.       <div id="dashboard-content">
  412.         <StickyToolRight />
  413.         <div className="kt-subheader kt-grid__item" id="kt_subheader">
  414.           <div className="kt-subheader__main">
  415.             <Breadcrumb>
  416.               <Breadcrumb.Item>
  417.                 <Link to="/pfpd-dashboard">PFPD</Link>
  418.               </Breadcrumb.Item>
  419.               <Breadcrumb.Item>
  420.                 <Link to="/pfpd-pencarian">Pencarian</Link>
  421.               </Breadcrumb.Item>
  422.             </Breadcrumb>
  423.           </div>
  424.           <div className="kt-subheader__main">
  425.             <Dropdown overlay={menu} placement="bottomCenter">
  426.               <Button>Hari Ini : {this.state.date}</Button>
  427.             </Dropdown>
  428.  
  429.             <Menu mode="horizontal">
  430.               <Menu.Item>
  431.                 <Link to="/pfpd-dashboard">
  432.                   <Icon type="dashboard" />
  433.                   Dashboard
  434.                 </Link>
  435.               </Menu.Item>
  436.  
  437.               <Menu.Item style={{ fontWeight: "bold" }}>
  438.                 <Icon type="unordered-list" />
  439.                 Pencarian
  440.               </Menu.Item>
  441.  
  442.               <Menu.Item>
  443.                 <Link to="/pfpd-laporan">
  444.                   <Icon type="solution" />
  445.                   Laporan
  446.                 </Link>
  447.               </Menu.Item>
  448.             </Menu>
  449.           </div>
  450.         </div>
  451.         <Row>
  452.           <Card
  453.             title={
  454.               <div>
  455.                 <Icon
  456.                   type="unordered-list"
  457.                   style={{
  458.                     marginRight: 20,
  459.                   }}
  460.                 />
  461.                 Daftar Pemberitahuan Pabean
  462.               </div>
  463.             }
  464.           >
  465.             <Alert
  466.               message="Catatan"
  467.               description="Gunakan 1 Klik pada Row untuk Preview,  Gunakan 2 Klik untuk Periksa Dokumen"
  468.               // description="Gunakan 2 Klik pada Row untuk langsung memeriksa"
  469.               type="info"
  470.               showIcon
  471.               style={{ width: 400 }}
  472.               closable
  473.             />
  474.             <Drawer
  475.               title="Data Header"
  476.               // placement={this.state.placement}
  477.               closable={true}
  478.               onClose={this.onClose}
  479.               visible={this.state.sidebarLeft}
  480.               width={480}
  481.             >
  482.               <Tabs type="card" tabPosition="top">
  483.                 <TabPane
  484.                   tab={
  485.                     <span>
  486.                       <i
  487.                         class="fa fa-building"
  488.                         aria-hidden="true"
  489.                         style={{ marginRight: 15 }}
  490.                       ></i>
  491.                       Identitas Perusahaan
  492.                     </span>
  493.                   }
  494.                   key="66"
  495.                 >
  496.                   <IdentitasPerusahaan />
  497.                   {this.state.showRedirect ? (
  498.                     <div className="mt-4 text-center">
  499.                       <button
  500.                         className="btn btn-primary"
  501.                         onClick={this.onRedirect}
  502.                       >
  503.                         <i
  504.                           className="fas fa-eye"
  505.                           style={{ marginRight: 10 }}
  506.                         ></i>
  507.                         Periksa Dokumen
  508.                       </button>
  509.                     </div>
  510.                   ) : null}
  511.                 </TabPane>
  512.                 <TabPane
  513.                   tab={
  514.                     <span>
  515.                       <i
  516.                         class="fa fa-user"
  517.                         aria-hidden="true"
  518.                         style={{ marginRight: 15 }}
  519.                       ></i>
  520.                       Data Pengawas
  521.                     </span>
  522.                   }
  523.                   key="76"
  524.                 >
  525.                   <table class="table">
  526.                     <thead>
  527.                       <tr>
  528.                         <th scope="col">Fungsi Tugas</th>
  529.                         <th scope="col">NIP</th>
  530.                         <th scope="col">Nama</th>
  531.                         <th scope="col">Waktu Tunjuk</th>
  532.                       </tr>
  533.                     </thead>
  534.                     <tbody>
  535.                       <tr>
  536.                         <th scope="row">PFPB Periksa Barang</th>
  537.                         <td>19839889202973</td>
  538.                         <td>JUNAIDI A.</td>
  539.                         <td>2020-04-21 09:45:50</td>
  540.                       </tr>
  541.                     </tbody>
  542.                   </table>
  543.                 </TabPane>
  544.               </Tabs>
  545.             </Drawer>
  546.             <Spin spinning={this.state.isLoad}>
  547.               <div class="tbl">
  548.                 <div
  549.                   class="text-right pl-2 pb-2"
  550.                   style={
  551.                     {
  552.                       // marginRight : 100
  553.                     }
  554.                   }
  555.                 >
  556.                   <button class="btn btn-secondary" onClick={this.handleReset}>
  557.                     Reload Data
  558.                   </button>
  559.                 </div>
  560.                 <DataGrid
  561.                   id={"gridContainer"}
  562.                   onRowDblClick={this.onSelectionChanged}
  563.                   onRowClick={this.triggers}
  564.                   keyExpr={"idHeader"}
  565.                   dataSource={newData}
  566.                   allowColumnReordering={true}
  567.                   allowColumnResizing={true}
  568.                   hoverStateEnabled={true}
  569.                   showColumnLines={true}
  570.                   columnAutoWidth={true}
  571.                   showBorders={true}
  572.                   selection={{ mode: "single" }}
  573.                 >
  574.                   <Export
  575.                     enabled={true}
  576.                     fileName={"Daftar Pemberitahuan Pabean"}
  577.                   />
  578.                   <ColumnChooser enabled={true} />
  579.                   <FilterRow visible={true} />
  580.                   <HeaderFilter visible={true} />
  581.                   <Paging defaultPageSize={10} />
  582.                   <Pager
  583.                     showPageSizeSelector={true}
  584.                     allowedPageSizes={[5, 10, 20]}
  585.                     showInfo={true}
  586.                   />
  587.  
  588.                   {/*
  589.                       <Column
  590.                       caption={'AKSI'}
  591.                       dataField={'idHeader'}
  592.                       type={'buttons'}
  593.                       buttons={[{
  594.                         icon: 'search',
  595.                         hint: 'Lihat',
  596.                         text: 'Lihat'
  597.                       }]}
  598.                       />
  599.                     */}
  600.  
  601.                   <Column
  602.                     dataField={"kodeDokumen"}
  603.                     caption={"JENIS PEMBERITAHUAN"}
  604.                     dataType={"string"}
  605.                     // filterOperations={[]}
  606.                     // filterValue={this.props.input.kodeDokumen}
  607.                     allowFiltering={true}
  608.                     allowSorting={false}
  609.                   >
  610.                     <HeaderFilter visible={true} />
  611.                   </Column>
  612.                   <Column
  613.                     dataField={"nomorAju"}
  614.                     caption={"NOMOR AJU"}
  615.                     dataType={"string"}
  616.                     // filterValue={this.props.input.nomorAju}
  617.                     // filterOperations={[]}
  618.                     allowFiltering={true}
  619.                     allowSorting={false}
  620.                   />
  621.                   <Column
  622.                     dataField={"nomorDaftar"}
  623.                     caption={"NOMOR DAFTAR"}
  624.                     dataType={"string"}
  625.                     // filterValue={this.props.input.nomorDaftar}
  626.                     // filterOperations={[]}
  627.                     allowFiltering={true}
  628.                     allowSorting={false}
  629.                   />
  630.  
  631.                   <Column
  632.                     dataField={"tanggalDaftar"}
  633.                     dataType={"date"}
  634.                     format="dd-MM-yyyy"
  635.                     // filterValue={
  636.                     //   this.props.input.tanggalDaftar
  637.                     //     ? this.props.input.tanggalDaftar
  638.                     //     : null
  639.                     // }
  640.                     // filterOperations={[]}
  641.                     caption={"TANGGAL DAFTAR"}
  642.                     allowFiltering={true}
  643.                     allowSorting={false}
  644.                   />
  645.                   <Column
  646.                     dataField={"namaEntitasUsaha"}
  647.                     // filterValue={this.props.input.namaEntitasUsaha}
  648.                     caption={"PENGUSAHA"}
  649.                     // filterOperations={[]}
  650.                     dataType={"string"}
  651.                     allowFiltering={true}
  652.                     allowSorting={false}
  653.                   />
  654.                   <Column
  655.                     dataField={"namaEntitasPpjk"}
  656.                     // filterValue={this.props.input.namaEntitasPpjk}
  657.                     caption={"PPJK"}
  658.                     // filterOperations={[]}
  659.                     dataType={"string"}
  660.                     allowFiltering={true}
  661.                     allowSorting={false}
  662.                   />
  663.                   <Column
  664.                     dataField={"umur"}
  665.                     selectedFilterOperation={this.props.input.operatorUmur}
  666.                     // filterValue={this.props.input.umur}
  667.                     caption={"UMUR"}
  668.                     dataType={"number"}
  669.                     allowFiltering={true}
  670.                     allowSorting={false}
  671.                   />
  672.                   <Column
  673.                     dataField={"kodeJalur"}
  674.                     // filterValue={this.props.input.kodeJalur}
  675.                     caption={"JALUR"}
  676.                     style={{ color: "red" }}
  677.                     cellRender={renderGridCell}
  678.                     // filterOperations={[]}
  679.                     dataType={"string"}
  680.                     allowFiltering={true}
  681.                     allowSorting={false}
  682.                   />
  683.                   <Column
  684.                     dataField={"status"}
  685.                     // filterValue={this.props.input.status}
  686.                     caption={"STATUS"}
  687.                     // filterOperations={[]}
  688.                     dataType={"string"}
  689.                     customizeText={(cellInfo) => {
  690.                       return cellInfo.value ? cellInfo.value[0].namaProses : "";
  691.                     }}
  692.                     allowFiltering={true}
  693.                     allowSorting={false}
  694.                   />
  695.                 </DataGrid>
  696.               </div>
  697.             </Spin>
  698.           </Card>
  699.         </Row>
  700.       </div>
  701.     );
  702.   }
  703. }
  704.  
  705. const mapStateToProps = (state) => {
  706.   return {
  707.     isLoad: state.pfpd.pfpdLoading,
  708.     npd: state.pfpd.npdData.data || {},
  709.     listDokumen: state.pfpd.listReferensi.data || {},
  710.     pfpd: state.pfpd,
  711.     // data: state.pfpd.browse.data.listData,
  712.     input: state.core.input || {},
  713.     nip: state.auth.user.nip || {},
  714.     kodeKantor: state.auth.user.kodeKantor || {},
  715.   };
  716. };
  717. const mapDispatchToProps = {
  718.   getNPDPFPD,
  719.   setInput,
  720.   setLoading,
  721.   getDokumen,
  722.   getBrowsePFPD,
  723.   getDokumenPabeanPFPD,
  724.   getDokumenPabeanDashboardPFPD,
  725.   getMaxSeriBarangPFPD,
  726.   getCekPeriksaMerahPFPD,
  727.   getListBarangPFPD,
  728.   getListBarangPFPD2,
  729.   getListDokapPFPD,
  730.   resetInput,
  731.   setMultiInput,
  732.   setLogin,
  733.   getReferensiDokumen,
  734.   resetDokumenPabeanFPD,
  735.   resetSave,
  736. };
  737.  
  738. export default withRouter(
  739.   connect(mapStateToProps, mapDispatchToProps)(PfpdPencarian)
  740. );
Add Comment
Please, Sign In to add comment