Dashboard sipadu mbip
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

DatatableKT.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import React, { Component } from 'react';
  2. import { Modal } from 'react-bootstrap';
  3. import ClipLoader from 'react-spinners/ClipLoader';
  4. import axios from 'axios';
  5. export default class DatatableKT extends Component {
  6. constructor(props) {
  7. super(props);
  8. this.state = {
  9. data: props.data,
  10. currentUrl: props.url,
  11. showModal: false,
  12. processing: false,
  13. responseMessage: '',
  14. form : {
  15. current_id: props.current_id,
  16. id: '',
  17. status: 'Belum Bayar',
  18. remark: '',
  19. amount: '',
  20. },
  21. };
  22. this.onSubmit = this.onSubmit.bind(this);
  23. this.onChangeStatus = this.onChangeStatus.bind(this);
  24. this.onChangeRemark = this.onChangeRemark.bind(this);
  25. this.onChangeAmount = this.onChangeAmount.bind(this);
  26. this.closeModal = this.closeModal.bind(this);
  27. }
  28. onChangeStatus(e){
  29. let value = e.target.value;
  30. this.setState(prevState => ({
  31. form: {
  32. ...prevState.form,
  33. status: value,
  34. }
  35. }));
  36. }
  37. onChangeRemark(e){
  38. let value = e.target.value;
  39. this.setState(prevState => ({
  40. form: {
  41. ...prevState.form,
  42. remark: value,
  43. }
  44. }));
  45. }
  46. onChangeAmount(e){
  47. let value = e.target.value;
  48. this.setState(prevState => ({
  49. form: {
  50. ...prevState.form,
  51. amount: value,
  52. }
  53. }));
  54. }
  55. onUpdateStatus(e){
  56. this.setState(prevState => ({
  57. form: {
  58. ...prevState.form,
  59. id: e,
  60. }
  61. }));
  62. this.setState({ showModal: true });
  63. }
  64. closeModal() {
  65. this.setState({ showModal: false });
  66. }
  67. onSubmit(e){
  68. e.preventDefault();
  69. let input = prompt("Adakah anda pasti kemaskini status kompaun ini? \nTaip 'yes' untuk teruskan", "");
  70. if (input == "yes") {
  71. this.setState({ processing: true });
  72. let formData = this.state.form;
  73. axios.post("/api/update/compound/via-dashboard", formData).then(response => {
  74. if (response.data.success) {
  75. fetch(this.state.currentUrl).then(response => {
  76. response.json().then(res => {
  77. this.setState({ processing: false });
  78. this.setState({ data: res.data, showModal: false });
  79. })
  80. })
  81. this.setState({ responseMessage: response.data.message });
  82. alert(response.data.message);
  83. }else{
  84. alert(response.data.message);
  85. this.setState({ showModal: false, processing: false, responseMessage: response.data.message });
  86. }
  87. }).catch(error =>{
  88. console.log(error);
  89. });
  90. }else{
  91. alert('Kemaskini status dibatalkan');
  92. this.setState({ showModal: false });
  93. }
  94. }
  95. render() {
  96. return(
  97. <div>
  98. <div className="data_table_main dt-responsive table-responsive">
  99. <table id="compoundKT" className="table table-sm table-striped table-bordered nowrap" width="100%">
  100. <thead>
  101. <tr>
  102. <th>#</th>
  103. <th>Kpd</th>
  104. <th>Jenis</th>
  105. <th>Tarikh Masa</th>
  106. <th>Kesalahan</th>
  107. <th width="110">Kadar Kompaun</th>
  108. <th>Nric</th>
  109. <th>Nama</th>
  110. <th>PenguatKuasa</th>
  111. <th>Status</th>
  112. <th>Tindakan</th>
  113. </tr>
  114. </thead>
  115. <tbody>
  116. { this.state.data.length > 0 ?
  117. this.state.data.map((item,i) =>
  118. <tr key={i}>
  119. <td>
  120. {item.DT_RowIndex}
  121. </td>
  122. <td>
  123. {item.index !== "" ?<div><small className='label label-success'>{item.index}</small>&nbsp;{item.kpd}</div> : <div>{item.kpd}</div>}
  124. </td>
  125. <td>{item.jenis}</td>
  126. <td>{item.tarikh_masa}</td>
  127. <td>Seksyen {item.kesalahan.sketr} <br/> {item.kesalahan.nama}</td>
  128. <td>{item.jumlah_kemaskini_kompaun !== "" ? <div>{item.jumlah_kemaskini_kompaun}</div> : <div>{item.jumlah_asal_kompaun}</div>}</td>
  129. <td>{item.nric}</td>
  130. <td>{item.nama}</td>
  131. <td>{item.enforcer.no_badan}, {item.enforcer.full_name}</td>
  132. <td>
  133. {
  134. item.catatan_dari_admin !== null ?
  135. item.status !== "Belum Bayar" ?
  136. <div>
  137. <div><b>{item.status}</b></div>
  138. <div style={{ "marginTop": "8px"}}>
  139. <span>Bayaran: </span><br/>
  140. RM {item.amount_payment}
  141. </div>
  142. <div style={{ "marginTop": "8px"}}>
  143. <span>Catatan: </span><br/>
  144. {item.catatan_dari_admin}
  145. </div>
  146. <div style={{ "marginTop": "8px"}}>
  147. <span>Kemaskini: </span><br/>
  148. {item.updated_at} <br/>
  149. {item.updated_by !== null ?
  150. <div>{item.updated_by.no_badan}</div>
  151. : ""
  152. }
  153. </div>
  154. </div>
  155. :
  156. <div>
  157. <div><b>{item.status}</b></div>
  158. <div style={{ "marginTop": "8px"}}>
  159. <span>Catatan: </span><br/>
  160. {item.catatan_dari_admin}
  161. </div>
  162. <div style={{ "marginTop": "8px"}}>
  163. <span>Kemasikini: </span><br/>
  164. {item.updated_at} <br/>
  165. {item.updated_by !== null ?
  166. <div>{item.updated_by.no_badan}</div>
  167. : ""
  168. }
  169. </div>
  170. </div>
  171. :
  172. <div><b>{item.status}</b></div>
  173. }
  174. </td>
  175. <td style={{ "textAlign": "center" }}>
  176. <a href={"/main/compound/"+item.kpd+"/index"} className="btn btn-info btn-sm waves-effect waves-light">
  177. TERUSKAN
  178. </a>
  179. <button data-toggle="modal" data-target="#ajaxModel" onClick={this.onUpdateStatus.bind(this, item._id)} className="btn btn-primary btn-sm waves-effect waves-light">
  180. KEMASKINI STATUS
  181. </button>
  182. <a href={"/main/edit/compound/"+item._id} className="btn btn-danger btn-sm waves-effect waves-light">
  183. KEMASKINI
  184. </a>
  185. </td>
  186. </tr>
  187. )
  188. :
  189. <tr>
  190. <td colSpan="11" style={{ "textAlign": "center" }}>Tiada Data Ditemui</td>
  191. </tr>
  192. }
  193. </tbody>
  194. <tfoot>
  195. <tr>
  196. <th>#</th>
  197. <th>Kpd</th>
  198. <th>Jenis</th>
  199. <th>Tarikh Masa</th>
  200. <th>Kesalahan</th>
  201. <th width="110">Kadar Kompaun</th>
  202. <th>Nric</th>
  203. <th>Nama</th>
  204. <th>PenguatKuasa</th>
  205. <th>Status</th>
  206. <th>Tindakan</th>
  207. </tr>
  208. </tfoot>
  209. </table>
  210. </div>
  211. <Modal size="lg" show={this.state.showModal} onHide={this.closeModal}>
  212. <form className="form-horizontal" onSubmit={this.onSubmit}>
  213. <Modal.Header closeButton>
  214. <Modal.Title>Kemaskini Status Kompaun</Modal.Title>
  215. </Modal.Header>
  216. <Modal.Body>
  217. <div className="modal-body">
  218. {!this.state.processing ?
  219. ''
  220. :
  221. <div className='sweet-loading' style={{'textAlign':'center'}}>
  222. <ClipLoader
  223. style={{'border-color': 'red'}}
  224. sizeUnit={"px"}
  225. size={50}
  226. color={'#123abc'}
  227. loading={this.state.processing}
  228. />
  229. </div>
  230. }
  231. <input type="hidden" name="compound_id" id="compound_id" value={this.state.form.id} />
  232. <div className="form-group">
  233. <label className="col-sm-6 control-label"><b>Status</b></label>
  234. <div className="col-sm-12">
  235. <select className="form-control" required value={this.state.form.status} onChange={this.onChangeStatus}>
  236. <option key="Belum Bayar" value="Belum Bayar">Belum Bayar</option>
  237. <option key="Berbayar" value="Berbayar">Berbayar</option>
  238. <option key="Batal" value="Batal">Batal</option>
  239. </select>
  240. </div>
  241. </div>
  242. <div className="form-group">
  243. <label className="col-sm-6 control-label"><b>Catatan <code>*</code></b></label>
  244. <div className="col-sm-12">
  245. <textarea className="form-control" value={this.state.form.remark} onChange={this.onChangeRemark}/>
  246. </div>
  247. </div>
  248. <div className="form-group">
  249. <label className="col-sm-6 control-label"><b>Jumlah Dibayar <code>*</code></b></label>
  250. <div className="col-sm-12">
  251. <input type="number" steps="0.00" className="form-control" placeholder="0.0" value={this.state.form.amount} onChange={this.onChangeAmount} required/>
  252. </div>
  253. </div>
  254. </div>
  255. </Modal.Body>
  256. <Modal.Footer>
  257. <button type="button" className="btn btn-sm btn-default waves-effect" onClick={this.closeModal}>Close</button>
  258. <button type="submit" className="btn btn-sm btn-primary waves-effect waves-light">KEMASKINI</button>
  259. </Modal.Footer>
  260. </form>
  261. </Modal>
  262. </div>
  263. )
  264. }
  265. }