Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.98 KB | None | 0 0
  1. <div class="card-body">
  2. <h3 align="center"><?php echo $products; ?></h3>
  3. <table align="center">
  4. <thead>
  5. <tr>
  6. <th style="text-align:center;"><?php echo $code; ?></th>
  7. <th style="text-align:center;"><?php echo $product; ?></th>
  8. <th style="text-align:center;"><?php echo $quantity.' '.$total; ?> <a href="showproducts.php" target="_blank"><i class="fas fa-edit text-danger"></i></a></th>
  9. <th style="text-align:center;"><?php echo $quantity; ?></th>
  10. <th style="text-align:center;"><?php echo $price.' '.$unit; ?></th>
  11. <th style="text-align:center;"><?php echo $price.' '.$total; ?></th>
  12. </tr>
  13. </thead>
  14. <tr>
  15. <td>
  16. <input name="codebar" onchange="codefetch()" type="text" class="form-control form-control-sm"></td>
  17. </td>
  18. <td>
  19. <input type="text" name="product" onchange="autofill()" id="prodname" class="form-control form-control-sm" autocomplete="off" placeholder="<?php echo $prodname; ?>" />
  20. </td>
  21. <td><div class=""><input id="quantity" name="quantity" readonly type="text" class="form-control form-control-sm"></td>
  22. <td><input id="neededquantity" name="neededquantity" type="text" class="form-control form-control-sm"></td>
  23. <td><input id="sellprice" name="sellprice" type="text" class="form-control form-control-sm sellprice"></td>
  24. <td><input id="totalprice" name="totalprice" readonly type="text" class="form-control form-control-sm"></td>
  25. </tr>
  26. <tbody id="orderTable">
  27. </tbody>
  28. </table>
  29. <center style="padding:10px;">
  30. <button id="add" style="width:150px;" onclick="addRow()" class="btn btn-success">Add</button>
  31. <button id="remove" style="width:150px;" class="btn btn-danger">Remove</button>
  32. </center>
  33. </div>
  34. </div>
  35.  
  36. function autofill(){
  37.  
  38. var name = $('input[name=product]').val();
  39. $.ajax({
  40. url: 'gpin.php',
  41. data: 'name='+name,
  42. success: function (data){
  43. var json = data;
  44. obj = JSON.parse(json);
  45. $('input[name=quantity]').val(obj.quantity);
  46. $('input[name=sellprice]').val(obj.sellprice);
  47. $('input[name=codebar]').val(obj.code);
  48. }
  49. });
  50. }
  51.  
  52. function codefetch(){
  53. var code = $("input[name=codebar]").val();
  54. $.ajax({
  55. url: 'gpic.php',
  56. data: 'code='+code,
  57. success: function (data){
  58. var json = data;
  59. obj = JSON.parse(json);
  60. $('input[name=product]').val(obj.name);
  61. $('input[name=quantity]').val(obj.quantity);
  62. $('input[name=sellprice]').val(obj.sellprice);
  63. }
  64. });
  65. }
  66.  
  67. $(document).ready(function(){
  68.  
  69. $('#prodname').typeahead({
  70. source: function(query, result)
  71. {
  72. $.ajax({
  73. url:"prodnameautofill.php",
  74. method:"POST",
  75. data:{query:query},
  76. dataType:"json",
  77. success:function(data)
  78. {
  79. result($.map(data, function(item){
  80. return item;
  81. }));
  82. }
  83. })
  84. }
  85. });
  86.  
  87. });
  88.  
  89.  
  90. function calculate() {
  91. var myBox1 = $('input[name=neededquantity]').val();
  92. var myBox2 = $('input[name=sellprice]').val();
  93. var result = $('input[name=totalprice]').val();
  94. var myResult = myBox1 * myBox2;
  95. $('input[name=totalprice]').val(myResult);
  96. var quantity = $('input[name=quantity]').val();
  97. var neededquantity = $('input[name=neededquantity]').val();
  98. var myResult2 = quantity - neededquantity;
  99. if (myResult2 < 0){
  100. document.getElementsByName('neededquantity').className = ('form-control form-control-sm bg-danger text-light');
  101. }
  102. else {
  103. document.getElementsByName('neededquantity')[0].className = ('form-control form-control-sm bg-success text-light');
  104. }
  105. }
  106.  
  107. function addRow() {
  108. var table = document.getElementById("orderTable");
  109. var row = table.insertRow(0);
  110. var cell1 = row.insertCell(0);
  111. var cell2 = row.insertCell(1);
  112. var cell3 = row.insertCell(2);
  113. var cell4 = row.insertCell(3);
  114. var cell5 = row.insertCell(4);
  115. var cell6 = row.insertCell(5);
  116. cell1.innerHTML = '<input name="codebar" onchange="codefetch()" type="text" class="form-control form-control-sm">';
  117. cell2.innerHTML = '<input type="text" name="product" onchange="autofill()" id="prodname" class="form-control form-control-sm" autocomplete="off" placeholder="<?php echo $prodname; ?>" />';
  118. cell3.innerHTML = '<input name="quantity" readonly type="text" class="form-control form-control-sm">';
  119. cell4.innerHTML = '<input name="neededquantity" type="text" oninput="calculate();" class="form-control form-control-sm">';
  120. cell5.innerHTML = '<input name="sellprice" type="text" oninput="calculate();" class="form-control form-control-sm sellprice">';
  121. cell6.innerHTML = '<input name="totalprice" readonly type="text" class="form-control form-control-sm">';
  122. }
  123.  
  124. cell2.innerHTML = '<input type="text" name="product" onchange="autofill()" id="prodname" class="form-control form-control-sm" autocomplete="off" placeholder="<?php echo $prodname; ?>" />';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement