Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DatatableParkir.js 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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 DatatableParkir 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="compoundParkir" className="table table-sm table-striped table-bordered nowrap dataTable" 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>Kadar Kompaun</th>
  108. <th>No Plat</th>
  109. <th>PenguatKuasa</th>
  110. <th width="110">Status</th>
  111. <th>Tindakan</th>
  112. </tr>
  113. </thead>
  114. <tbody>
  115. { this.state.data.length > 0 ?
  116. this.state.data.map((item,i) =>
  117. <tr key={i}>
  118. <td>
  119. {item.DT_RowIndex}
  120. </td>
  121. <td>
  122. {item.index !== "" ?<div><small className='label label-success'>{item.index}</small>&nbsp;{item.kpd}</div> : <div>{item.kpd}</div>}
  123. </td>
  124. <td>{item.jenis}</td>
  125. <td>{item.tarikh_masa}</td>
  126. <td>Seksyen {item.kesalahan.sketr} <br/> {item.kesalahan.nama}</td>
  127. <td>{item.jumlah_kemaskini_kompaun !== "" ? <div>{item.jumlah_kemaskini_kompaun}</div> : <div>{item.jumlah_asal_kompaun}</div>}</td>
  128. <td>{item.no_plate}</td>
  129. <td>{item.enforcer.no_badan}, {item.enforcer.full_name}</td>
  130. <td>
  131. {
  132. item.catatan_dari_admin !== null ?
  133. item.status !== "Belum Bayar" ?
  134. <div>
  135. <div><b>{item.status}</b></div>
  136. <div style={{ "marginTop": "8px"}}>
  137. <span>Bayaran: </span><br/>
  138. RM {item.amount_payment}
  139. </div>
  140. <div style={{ "marginTop": "8px"}}>
  141. <span>Catatan: </span><br/>
  142. {item.catatan_dari_admin}
  143. </div>
  144. <div style={{ "marginTop": "8px"}}>
  145. <span>Kemaskini: </span><br/>
  146. {item.updated_at} <br/>
  147. {item.updated_by !== null ?
  148. <div>{item.updated_by.no_badan}</div>
  149. : ""
  150. }
  151. </div>
  152. </div>
  153. :
  154. <div>
  155. <div><b>{item.status}</b></div>
  156. <div style={{ "marginTop": "8px"}}>
  157. <span>Catatan: </span><br/>
  158. {item.catatan_dari_admin}
  159. </div>
  160. <div style={{ "marginTop": "8px"}}>
  161. <span>Kemasikini: </span><br/>
  162. {item.updated_at} <br/>
  163. {item.updated_by !== null ?
  164. <div>{item.updated_by.no_badan}</div>
  165. : ""
  166. }
  167. </div>
  168. </div>
  169. :
  170. <div><b>{item.status}</b></div>
  171. }
  172. </td>
  173. <td style={{ "textAlign": "center" }}>
  174. <a href={"/main/compound/"+item.kpd+"/index"} className="btn btn-info btn-sm waves-effect waves-light">
  175. TERUSKAN
  176. </a>
  177. <button data-toggle="modal" data-target="#ajaxModel" onClick={this.onUpdateStatus.bind(this, item._id)} className="btn btn-primary btn-sm waves-effect waves-light">
  178. KEMASKINI STATUS
  179. </button>
  180. <a href={"/main/edit/compound/"+item._id} className="btn btn-danger btn-sm waves-effect waves-light">
  181. KEMASKINI
  182. </a>
  183. </td>
  184. </tr>
  185. )
  186. :
  187. <tr>
  188. <td colSpan="10" style={{ "textAlign": "center" }}>Tiada Data Ditemui</td>
  189. </tr>
  190. }
  191. </tbody>
  192. <tfoot>
  193. <tr>
  194. <th>#</th>
  195. <th>Kpd</th>
  196. <th>Jenis</th>
  197. <th>Tarikh Masa</th>
  198. <th>Kesalahan</th>
  199. <th>Kadar Kompaun</th>
  200. <th>No Plat</th>
  201. <th>PenguatKuasa</th>
  202. <th width="110">Status</th>
  203. <th>Tindakan</th>
  204. </tr>
  205. </tfoot>
  206. </table>
  207. </div>
  208. <Modal size="lg" show={this.state.showModal} onHide={this.closeModal}>
  209. <form className="form-horizontal" onSubmit={this.onSubmit}>
  210. <Modal.Header closeButton>
  211. <Modal.Title>Kemaskini Status Kompaun</Modal.Title>
  212. </Modal.Header>
  213. <Modal.Body>
  214. <div className="modal-body">
  215. {!this.state.processing ?
  216. ''
  217. :
  218. <div className='sweet-loading' style={{'textAlign':'center'}}>
  219. <ClipLoader
  220. style={{'border-color': 'red'}}
  221. sizeUnit={"px"}
  222. size={50}
  223. color={'#123abc'}
  224. loading={this.state.processing}
  225. />
  226. </div>
  227. }
  228. <input type="hidden" name="compound_id" id="compound_id" value={this.state.form.id} />
  229. <div className="form-group">
  230. <label className="col-sm-6 control-label"><b>Status</b></label>
  231. <div className="col-sm-12">
  232. <select className="form-control" required value={this.state.form.status} onChange={this.onChangeStatus}>
  233. <option key="Belum Bayar" value="Belum Bayar">Belum Bayar</option>
  234. <option key="Berbayar" value="Berbayar">Berbayar</option>
  235. <option key="Batal" value="Batal">Batal</option>
  236. </select>
  237. </div>
  238. </div>
  239. <div className="form-group">
  240. <label className="col-sm-6 control-label"><b>Catatan <code>*</code></b></label>
  241. <div className="col-sm-12">
  242. <textarea className="form-control" value={this.state.form.remark} onChange={this.onChangeRemark}/>
  243. </div>
  244. </div>
  245. <div className="form-group">
  246. <label className="col-sm-6 control-label"><b>Jumlah Dibayar <code>*</code></b></label>
  247. <div className="col-sm-12">
  248. <input type="number" steps="0.00" className="form-control" placeholder="0.0" value={this.state.form.amount} onChange={this.onChangeAmount} required/>
  249. </div>
  250. </div>
  251. </div>
  252. </Modal.Body>
  253. <Modal.Footer>
  254. <button type="button" className="btn btn-sm btn-default waves-effect" onClick={this.closeModal}>Close</button>
  255. <button type="submit" className="btn btn-sm btn-primary waves-effect waves-light">KEMASKINI</button>
  256. </Modal.Footer>
  257. </form>
  258. </Modal>
  259. </div>
  260. )
  261. }
  262. }