customersDetails.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <div id="page-customers">
  2. <div class="container-fluid">
  3. <div class="row">
  4. <div class="col-sm-6">
  5. <button class="btn btn-primary" onclick="document.getElementById('addForm').style.display = 'block';document.getElementById('editForm').style.display = 'none';document.getElementById('editVForm').style.display = 'none';document.getElementById('addVForm').style.display = 'none';document.getElementById('deleteForm').style.display = 'none';"> Add Customer </button>
  6. <table id="example" class="table display table-striped table-bordered table-hover table-sm" cellspacing="0" width="100%">
  7. <thead>
  8. <tr>
  9. <th></th>
  10. <th></th>
  11. <th>Id</th>
  12. <th>Name</th>
  13. <th>Credit Sale</th>
  14. </tr>
  15. </thead>
  16. <tfoot>
  17. <tr>
  18. <th></th>
  19. <th></th>
  20. <th>Id</th>
  21. <th>Name</th>
  22. <th>Credit Sale</th>
  23. </tr>
  24. </tfoot>
  25. </table>
  26. </div>
  27. <div class="col-sm-6">
  28. <!-- <input type="number" name="" id="loadVehicles"> -->
  29. <?php include "vehiclesVw.php" ?>
  30. <?php include "vehiclesDetails.php" ?>
  31. </div>
  32. </div>
  33. </div>
  34. <?php include "addCustomer.php" ?>
  35. <?php include "Edit.php" ?>
  36. <?php include "Delete.php" ?>
  37. <?php include "editVehicle.php" ?>
  38. <?php include "addVehicle.php" ?>
  39. <?php include "deleteVehicle.php" ?>
  40. </div>
  41. <script type="text/javascript">
  42. $(document).ready(function() {
  43. var table = $('#example').DataTable( {
  44. // "buttons": true,
  45. "ajax": "api/v1/Customers/customers.txt",
  46. "columns": [
  47. {
  48. "className": 'delete',
  49. "orderable": false,
  50. "data": null,
  51. "defaultContent": '<button class="btn btn-danger" style="width:40px;height:31px;"><i class="fa fa-trash-o"></i></button>',
  52. },
  53. {
  54. "className": 'edit',
  55. "orderable": false,
  56. "data": null,
  57. "defaultContent": '<button class="btn btn-info" style="width:40px;height:31px;"><i class="far fa-edit"><i></button>'
  58. },
  59. { "data": "Customer_Id" },
  60. { "data": "Name",
  61. "className":'name'
  62. },
  63. { "data": "Credit_Sale" },
  64. //{ "data": "Id" },
  65. //{ "data": "Number" },
  66. ],
  67. "order": [[1, 'asc']],
  68. select: true
  69. } );
  70. // Add event listener for opening and closing details
  71. $('#example tbody').on('click', 'td.name', function () {
  72. var tr = $(this).closest('tr');
  73. var row = table.row( tr );
  74. var username = row.data()['Name'];
  75. var idForVehicle = row.data()['Customer_Id'];
  76. document.cookie = "customerId="+idForVehicle;
  77. document.cookie = "customerName="+username;
  78. window.location.href = 'customers.php';
  79. } );
  80. // Add event listener for opening and closing details
  81. $('#example tbody').on('click', 'td.delete', function () {
  82. var tr = $(this).closest('tr');
  83. var row = table.row( tr );
  84. var username = row.data()['Name'];
  85. var id = row.data()['Customer_Id'];
  86. document.getElementById('deleteid').value = id;
  87. document.getElementById('deleteForm').style.display = 'block';
  88. document.getElementById('editForm').style.display = 'none';
  89. document.getElementById('addForm').style.display = 'none';
  90. } );
  91. // Add event listener for opening and closing details
  92. $('#example tbody').on('click', 'tr td.edit', function () {
  93. var tr = $(this).closest('tr');
  94. var row = table.row( tr );
  95. // console.log( table.row( this ).data() );
  96. // alert( table.row( this ).data()['Name'] );
  97. var username = row.data()['Name'];
  98. var creditSale = row.data()['Credit_Sale'];
  99. var id = row.data()['Customer_Id'];
  100. document.getElementById('username').value = username;
  101. document.getElementById('id').value = id;
  102. //document.getElementById('vehicle_id').value = vehicle_id;
  103. //document.getElementById('number').value = number;
  104. if (creditSale=='Yes') {
  105. document.getElementById('creditSaleOn').checked = true;
  106. }else if(creditSale=='No'){
  107. document.getElementById('creditSaleOff').checked = true;
  108. }
  109. document.getElementById('editForm').style.display = 'block';
  110. document.getElementById('addForm').style.display = 'none';
  111. document.getElementById('deleteForm').style.display = 'none';
  112. } );
  113. } );
  114. </script>