supplierDetails.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <button class="btn btn-primary" onclick="document.getElementById('addSForm').style.display = 'block';"> New supplier </button>
  2. <table id="supplier" class="table display table-striped table-bordered table-hover table-sm" cellspacing="0" width="100%">
  3. <thead>
  4. <tr>
  5. <th></th>
  6. <th></th>
  7. <th>Id</th>
  8. <th>Name</th>
  9. </tr>
  10. </thead>
  11. <tfoot>
  12. <tr>
  13. <th></th>
  14. <th></th>
  15. <th>Id</th>
  16. <th>Name</th>
  17. </tr>
  18. </tfoot>
  19. </table>
  20. <?php include "addSupplier.php" ?>
  21. <script type="text/javascript">
  22. $(document).ready(function() {
  23. var table = $('#supplier').DataTable( {
  24. "buttons": true,
  25. "ajax": "api/v1/Suppliers/suppliers.txt",
  26. "columns": [
  27. {
  28. "className": 'delete',
  29. "orderable": false,
  30. "data": null,
  31. "defaultContent": 'Delete'
  32. },
  33. {
  34. "className": 'edit',
  35. "orderable": false,
  36. "data": null,
  37. "defaultContent": 'Edit'
  38. },
  39. { "data": "Id" },
  40. { "data": "Name"},
  41. ],
  42. "order": [[1, 'asc']],
  43. select: true
  44. } );
  45. // Add event listener for opening and closing details
  46. $('#supplier tbody').on('click', 'td.delete', function () {
  47. var tr = $(this).closest('tr');
  48. var row = table.row( tr );
  49. var username = row.data()['Name'];
  50. var id = row.data()['Customer_Id'];
  51. document.getElementById('deleteid').value = id;
  52. document.getElementById('deleteForm').style.display = 'block';
  53. document.getElementById('editForm').style.display = 'none';
  54. document.getElementById('addForm').style.display = 'none';
  55. } );
  56. // Add event listener for opening and closing details
  57. $('#supplier tbody').on('click', 'tr td.edit', function () {
  58. var tr = $(this).closest('tr');
  59. var row = table.row( tr );
  60. var username = row.data()['Name'];
  61. var creditSale = row.data()['Credit_Sale'];
  62. var id = row.data()['Customer_Id'];
  63. document.getElementById('username').value = username;
  64. document.getElementById('id').value = id;
  65. if (creditSale=='Yes') {
  66. document.getElementById('creditSaleOn').checked = true;
  67. }else if(creditSale=='No'){
  68. document.getElementById('creditSaleOff').checked = true;
  69. }
  70. document.getElementById('editForm').style.display = 'block';
  71. document.getElementById('addForm').style.display = 'none';
  72. document.getElementById('deleteForm').style.display = 'none';
  73. } );
  74. } );
  75. </script>