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.

NewCompoundDataTable.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. import React, { Component } from 'react';
  2. import ReactDOM from 'react-dom';
  3. import ClipLoader from 'react-spinners/ClipLoader';
  4. import {ExportCSV} from '../ExportCSV';
  5. import DatatableParkir from './../DatatableParkir';
  6. import DatatablePelbagai from './../DatatablePelbagai';
  7. export default class NewCompoundDataTable extends Component {
  8. constructor(props) {
  9. super(props);
  10. this.state = {
  11. current_id: this.props.current_id,
  12. dataCompound: [],
  13. loading: 'null',
  14. current_url: 'null',
  15. total:{
  16. baru: this.props.baru,
  17. invest: this.props.invest,
  18. notice: this.props.notice,
  19. inven: this.props.inven,
  20. collap: this.props.collap,
  21. comp: this.props.comp
  22. },
  23. check: {
  24. kpd: true,
  25. date: true,
  26. faulty: true,
  27. enforcer: true,
  28. platno: false,
  29. companyno: false,
  30. nric: false,
  31. },
  32. form: {
  33. modul: this.props.modul,
  34. status: this.props.status,
  35. type: 'Parkir',
  36. kpd: '',
  37. start_date: new Date().getFullYear() + '-' + ("0" + (new Date().getMonth() + 1)).slice(-2) + '-' + ("0" + new Date().getDate()).slice(-2),
  38. end_date: new Date().getFullYear() + '-' + ("0" + (new Date().getMonth() + 1)).slice(-2) + '-' + ("0" + new Date().getDate()).slice(-2),
  39. faulty: 'All',
  40. enforcer: 'All',
  41. plate_no: '',
  42. company_no: '',
  43. nric: '',
  44. },
  45. list_enforcer: JSON.parse(this.props.enforcer),
  46. list_faulty: JSON.parse(this.props.faulty),
  47. };
  48. this.onCheckKpd = this.onCheckKpd.bind(this);
  49. this.onCheckDate = this.onCheckDate.bind(this);
  50. this.onCheckPlateNo = this.onCheckPlateNo.bind(this);
  51. this.onCheckCompanyNo = this.onCheckCompanyNo.bind(this);
  52. this.onCheckNric = this.onCheckNric.bind(this);
  53. this.onChangeKpd = this.onChangeKpd.bind(this);
  54. this.onChangeType = this.onChangeType.bind(this);
  55. this.onChangeStart = this.onChangeStart.bind(this);
  56. this.onChangeEnd = this.onChangeEnd.bind(this);
  57. this.onChangeFaulty = this.onChangeFaulty.bind(this);
  58. this.onChangeEnforcer = this.onChangeEnforcer.bind(this);
  59. this.onChangePlateNo = this.onChangePlateNo.bind(this);
  60. this.onChangeCompanyNo = this.onChangeCompanyNo.bind(this);
  61. this.onChangeNric = this.onChangeNric.bind(this);
  62. this.onChangeStatus = this.onChangeStatus.bind(this);
  63. this.onSubmit = this.onSubmit.bind(this);
  64. }
  65. onCheckKpd(e){
  66. this.setState(prevState => ({
  67. check: {
  68. ...prevState.check,
  69. kpd: !this.state.check.kpd
  70. },
  71. }))
  72. }
  73. onCheckDate(e){
  74. this.setState(prevState => ({
  75. check: {
  76. ...prevState.check,
  77. date: !this.state.check.date
  78. }
  79. }))
  80. }
  81. onCheckPlateNo(e){
  82. this.setState(prevState => ({
  83. check: {
  84. ...prevState.check,
  85. platno: !this.state.check.platno
  86. }
  87. }))
  88. }
  89. onCheckCompanyNo(e){
  90. this.setState(prevState => ({
  91. check: {
  92. ...prevState.check,
  93. companyno: !this.state.check.companyno
  94. }
  95. }))
  96. }
  97. onCheckNric(e){
  98. this.setState(prevState => ({
  99. check: {
  100. ...prevState.check,
  101. nric: !this.state.check.nric
  102. }
  103. }))
  104. }
  105. onChangeKpd(e){
  106. let value = e.target.value;
  107. this.setState(prevState => ({
  108. form: {
  109. ...prevState.form,
  110. kpd: value
  111. }
  112. }));
  113. }
  114. onChangeType(e){
  115. let value = e.target.value;
  116. this.setState(prevState => ({
  117. form: {
  118. ...prevState.form,
  119. type: value
  120. },
  121. loading: 'null',
  122. dataCompound: []
  123. }));
  124. }
  125. onChangeStart(e){
  126. let value = e.target.value;
  127. this.setState(prevState => ({
  128. form: {
  129. ...prevState.form,
  130. start_date: value
  131. }
  132. }));
  133. }
  134. onChangeEnd(e){
  135. let value = e.target.value;
  136. this.setState(prevState => ({
  137. form: {
  138. ...prevState.form,
  139. end_date: value
  140. }
  141. }));
  142. }
  143. onChangeFaulty(e){
  144. let value = e.target.value;
  145. this.setState(prevState => ({
  146. form: {
  147. ...prevState.form,
  148. faulty: value
  149. }
  150. }));
  151. }
  152. onChangeEnforcer(e){
  153. let value = e.target.value;
  154. this.setState(prevState => ({
  155. form: {
  156. ...prevState.form,
  157. enforcer: value
  158. }
  159. }));
  160. }
  161. onChangePlateNo(e){
  162. let value = e.target.value;
  163. this.setState(prevState => ({
  164. form: {
  165. ...prevState.form,
  166. plate_no: value
  167. }
  168. }));
  169. }
  170. onChangeCompanyNo(e){
  171. let value = e.target.value;
  172. this.setState(prevState => ({
  173. form: {
  174. ...prevState.form,
  175. company_no: value
  176. }
  177. }));
  178. }
  179. onChangeNric(e){
  180. let value = e.target.value;
  181. this.setState(prevState => ({
  182. form: {
  183. ...prevState.form,
  184. nric: value
  185. }
  186. }));
  187. }
  188. onChangeStatus(e){
  189. let value = e.target.value;
  190. this.setState(prevState => ({
  191. form: {
  192. ...prevState.form,
  193. status: value
  194. }
  195. }));
  196. }
  197. onSubmit(e){
  198. e.preventDefault();
  199. this.setState({ loading: true });
  200. let formData = {
  201. type: this.state.form.type,
  202. enforcer: this.state.form.enforcer,
  203. faulty: this.state.form.faulty,
  204. modul: this.state.form.modul,
  205. status: this.state.form.status,
  206. };
  207. if(this.state.check.date){
  208. formData = {
  209. ...formData,
  210. start_date: this.state.form.start_date,
  211. end_date: this.state.form.end_date,
  212. }
  213. }else{
  214. formData = {
  215. ...formData,
  216. start_date: '',
  217. end_date: '',
  218. }
  219. }
  220. if(this.state.check.kpd){
  221. formData = {
  222. ...formData,
  223. kpd: this.state.form.kpd,
  224. }
  225. }else if(this.state.check.platno){
  226. formData = {
  227. ...formData,
  228. plate_no: this.state.form.plate_no,
  229. }
  230. }else if(this.state.check.companyno){
  231. formData = {
  232. ...formData,
  233. company_no: this.state.form.company_no,
  234. }
  235. }else if(this.state.check.nric){
  236. formData = {
  237. ...formData,
  238. nric: this.state.form.nric,
  239. }
  240. }
  241. let queryString = Object.keys(formData).map(key => key + '=' + formData[key]).join('&');
  242. fetch('/api/list/compound?'+queryString).then(response => {
  243. response.json().then(res => {
  244. this.setState({ dataCompound: res.data, loading: false, current_url: '/api/list/compound?'+queryString });
  245. })
  246. })
  247. }
  248. render() {
  249. return (
  250. <div className="row">
  251. <div className="col-xl-2 col-md-12">
  252. <div className="panel panel-default">
  253. <div className="panel-heading">
  254. <h4 className="panel-title"> Modul Kategori </h4>
  255. </div>
  256. <div className="panel-body">
  257. <div><a href="/main/compound" className="active">Baru</a>&nbsp;<label className="badge badge-inverse-danger">{this.state.total.baru}</label></div>
  258. <div><a href="/main/compound/investigation">Pengesahan Kompaun</a>&nbsp;<label className="badge badge-success">{this.state.total.invest}</label></div>
  259. <div><a href="/main/compound/notice">Notis Amaran</a>&nbsp;<label className="badge badge-success">{this.state.total.notice}</label> </div>
  260. <div><a href="/main/compound/confiscated">Sitaan</a>&nbsp;<label className="badge badge-success">{this.state.total.inven}</label> </div>
  261. <div><a href="/main/compound/completed">Kompaun Dijelaskan</a>&nbsp;<label className="badge badge-success">{this.state.total.comp}</label></div>
  262. </div>
  263. </div>
  264. </div>
  265. <div className="col-xl-10 col-md-12">
  266. <div className="row">
  267. <div className="col-md-12">
  268. <div className="card">
  269. <div className="card-block">
  270. <form className="main cussPayment" onSubmit={this.onSubmit}>
  271. <div className="row clearfix">
  272. <div className="col-lg-3">
  273. <label><input type="checkbox" onClick={this.onCheckKpd} defaultChecked={true} />&nbsp;<b>No</b></label>
  274. <div className="input-group input-group-sm">
  275. <span className="input-group-prepend">
  276. <label className="input-group-text">KPD</label>
  277. </span>
  278. <input type="text" className="form-control form-control-sm" placeholder="SCM4744" value={this.state.form.kpd} onChange={this.onChangeKpd} required={this.state.check.kpd}/>
  279. </div>
  280. </div>
  281. <div className="col-lg-3">
  282. <label><b>Jenis Kompaun <code>*</code></b></label>
  283. <select className="form-control form-control-sm" value={this.state.form.type} onChange={this.onChangeType} required>
  284. <option>Parkir</option>
  285. <option>Pelbagai</option>
  286. </select>
  287. </div>
  288. </div>
  289. <div className="row clearfix" style={{marginBottom: "1.25em"}}>
  290. <div className="col-lg-12 col-md-12 col-sm-12 col-xs-12">
  291. <label><input type="checkbox" onClick={this.onCheckDate} defaultChecked={true} />&nbsp;<b>Tarikh</b></label>
  292. </div>
  293. <div className="col-lg-3">
  294. <input type="date" className=" form-control form-control-sm" value={this.state.form.start_date} onChange={this.onChangeStart} required={this.state.check.date}/>
  295. </div>
  296. <span><b>-</b></span>
  297. <div className="col-lg-3">
  298. <input type="date" className="form-control form-control-sm" value={this.state.form.end_date} onChange={this.onChangeEnd} />
  299. </div>
  300. </div>
  301. <div className="row clearfix" style={{marginBottom: "1.25em"}}>
  302. <div className="col-lg-12 col-md-12 col-sm-12 col-xs-12">
  303. <label><b>Seksyen Kesalahan</b></label>
  304. </div>
  305. <div className="col-lg-9 .offset-xl-3">
  306. <select className="form-control form-control-sm" defaultValue="All" onChange={this.onChangeFaulty} required={this.state.check.faulty}>
  307. <option value="All">All</option>
  308. {this.state.list_faulty.map((act,i) =>
  309. <optgroup label={act.nama} key={i}>
  310. {act.faulty.map((faulty,j) =>
  311. <option key={j} value={faulty._id}>Seksyen {faulty.sketr}</option>
  312. )}
  313. </optgroup>
  314. )}
  315. </select>
  316. </div>
  317. </div>
  318. <div className="row clearfix" style={{marginBottom: "1.25em"}}>
  319. <div className="col-lg-12 col-md-12 col-sm-12 col-xs-12">
  320. <label><b>PenguatKuasa</b></label>
  321. </div>
  322. <div className="col-lg-6 .offset-xl-6">
  323. <select className="form-control form-control-sm" defaultValue="All" onChange={this.onChangeEnforcer} required={this.state.check.enforcer}>
  324. <option value="All">All</option>
  325. {this.state.list_enforcer.map((staff, i) =>
  326. <option key={i} value={staff._id}>{staff.no_badan}, {staff.full_name}</option>
  327. )}
  328. </select>
  329. </div>
  330. </div>
  331. <div className="row clearfix" style={{marginBottom: "1.25em"}}>
  332. <div className="col-lg-3">
  333. <label><input type="checkbox" onClick={this.onCheckPlateNo} defaultChecked={false} />&nbsp;<b>No.Plat</b></label>
  334. <input type="text" className="form-control form-control-sm" placeholder="no plat" value={this.state.form.plate_no} onChange={this.onChangePlateNo} required={this.state.check.platno}/>
  335. </div>
  336. <div className="col-lg-3">
  337. <label><input type="checkbox" onClick={this.onCheckCompanyNo} defaultChecked={false} />&nbsp;<b> No.Syarikat</b></label>
  338. <input type="text" className="form-control form-control-sm" placeholder="no syarikat" value={this.state.form.company_no} onChange={this.onChangeCompanyNo} required={this.state.check.companyno}/>
  339. </div>
  340. <div className="col-lg-3">
  341. <label><input type="checkbox" onClick={this.onCheckNric} defaultChecked={false} />&nbsp;<b>NRIC</b></label>
  342. <input type="text" className="form-control form-control-sm" placeholder="nric" value={this.state.form.nric} onChange={this.onChangeNric} required={this.state.check.nric} />
  343. </div>
  344. </div>
  345. <div className="row clearfix" style={{marginBottom: "1.25em"}}>
  346. <div className="col-lg-12 col-md-12 col-sm-12 col-xs-12">
  347. <label><b>Status</b></label>
  348. </div>
  349. <div className="col-lg-3 .offset-xl-9">
  350. <select className="form-control form-control-sm" defaultValue="All" onChange={this.onChangeStatus} required>
  351. <option value="All">All</option>
  352. <option value="Belum Bayar">Belum Bayar</option>
  353. <option value="Batal">Batal</option>
  354. </select>
  355. </div>
  356. </div>
  357. <div className="form-group">
  358. <button type="submit" id="tapis" className="btn btn-info btn-sm waves-effect waves-light">Carian</button>
  359. </div>
  360. </form>
  361. </div>
  362. </div>
  363. </div>
  364. </div>
  365. </div>
  366. <div className="col-md-12">
  367. <div className="card">
  368. <div className="card-header">
  369. <h5>Senarai Kompaun</h5>
  370. { this.state.dataCompound.length > 0 ?
  371. <ExportCSV csvData={this.state.dataCompound} fileName="Report_saman_1" type={this.state.form.type} />
  372. : ''
  373. }
  374. </div>
  375. <div className="card-block contact-details">
  376. { this.state.loading !== 'null' ?
  377. !this.state.loading ?
  378. this.state.form.type === 'Parkir' ?
  379. <DatatableParkir data={this.state.dataCompound} url={this.state.current_url} current_id={this.state.current_id} />
  380. :
  381. <DatatablePelbagai data={this.state.dataCompound} url={this.state.current_url} current_id={this.state.current_id}/>
  382. :
  383. <div className='sweet-loading' style={{'textAlign':'center'}}>
  384. <ClipLoader
  385. style={{'border-color': 'red'}}
  386. sizeUnit={"px"}
  387. size={50}
  388. color={'#123abc'}
  389. loading={this.state.loading}
  390. />
  391. </div>
  392. : ''
  393. }
  394. </div>
  395. </div>
  396. </div>
  397. </div>
  398. );
  399. }
  400. }
  401. if (document.getElementById('newcompound')) {
  402. const component = document.getElementById('newcompound');
  403. const props = Object.assign({}, component.dataset)
  404. ReactDOM.render(<NewCompoundDataTable {...props} />, component);
  405. }