customersDetails.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <div >
  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": 'Delete'
  52. },
  53. {
  54. "className": 'edit',
  55. "orderable": false,
  56. "data": null,
  57. "defaultContent": 'Edit'
  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 = table.row( this ).data()['Name'];
  75. var idForVehicle = table.row( this ).data()['Customer_Id'];
  76. document.cookie = "customerId="+idForVehicle;
  77. document.cookie = "customerName="+username;
  78. //document.getElementById('loadVehicles').value = idForVehicle;
  79. //console.log( table.row( this ).data() );
  80. //alert( table.row( this ).data()['Customer_Id'] );
  81. //location.reload();
  82. window.location.href = 'customers.php';
  83. } );
  84. // Add event listener for opening and closing details
  85. $('#example tbody').on('click', 'td.delete', function () {
  86. var tr = $(this).closest('tr');
  87. var row = table.row( tr );
  88. var username = table.row( this ).data()['Name'];
  89. var id = table.row( this ).data()['Customer_Id'];
  90. document.getElementById('deleteid').value = id;
  91. document.getElementById('deleteForm').style.display = 'block';
  92. document.getElementById('editForm').style.display = 'none';
  93. document.getElementById('addForm').style.display = 'none';
  94. } );
  95. // Add event listener for opening and closing details
  96. $('#example tbody').on('click', 'tr td.edit', function () {
  97. var tr = $(this).closest('tr');
  98. var row = table.row( tr );
  99. // console.log( table.row( this ).data() );
  100. // alert( table.row( this ).data()['Name'] );
  101. var username = table.row( this ).data()['Name'];
  102. var creditSale = table.row( this ).data()['Credit_Sale'];
  103. var id = table.row( this ).data()['Customer_Id'];
  104. document.getElementById('username').value = username;
  105. document.getElementById('id').value = id;
  106. //document.getElementById('vehicle_id').value = vehicle_id;
  107. //document.getElementById('number').value = number;
  108. if (creditSale=='Yes') {
  109. document.getElementById('creditSaleOn').checked = true;
  110. }else if(creditSale=='No'){
  111. document.getElementById('creditSaleOff').checked = true;
  112. }
  113. document.getElementById('editForm').style.display = 'block';
  114. document.getElementById('addForm').style.display = 'none';
  115. document.getElementById('deleteForm').style.display = 'none';
  116. } );
  117. } );
  118. </script>