Guest User

Untitled

a guest
Jun 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. <?php
  2. $arrayNumber = 0;
  3. for($x = 1; $x < 3; $x++) { ?>
  4. <tr id="editRow<?php echo $x; ?>" class="<?php echo $arrayNumber; ?>">
  5. <td style="padding-left:20px;padding-right: 20px;">
  6. <div class="form-group">
  7. <select class="form-control" name="editRawName[]" id="editRawName<?php echo $x; ?>" onchange="getRawData(<?php echo $x; ?>)">
  8. <option value="">~~SELECT~~</option>
  9. <?php
  10. $rawSql = "SELECT * FROM raw_material WHERE status = 1";
  11. $rawData = $connect->query($rawSql);
  12.  
  13. while($row = $rawData->fetch_array()) {
  14. echo "<option value='".$row['raw_id']."' id='changeRaw".$row['raw_id']."'>".$row['raw_name']."</option>";
  15. } // /while
  16.  
  17. ?>
  18. </select>
  19. </div>
  20. </td>
  21. <td style="padding-left:20px;">
  22. <div class="form-group">
  23. <input type="number" name="editQuantity[]" id="editQuantity<?php echo $x; ?>" autocomplete="off" class="form-control" min="1"/>
  24. </div>
  25. </td>
  26. <td>
  27.  
  28. <button class="btn btn-default removeRawRowBtn" type="button" id="removeRawRowBtn" onclick="removeRawRow(<?php echo $x; ?>)"><i class="glyphicon glyphicon-trash"></i></button>
  29. </td>
  30. </tr>
  31. <?php
  32. $arrayNumber++;
  33. } // /for?>
  34.  
  35. function editProduct(productId = null) {
  36.  
  37. if(productId) {
  38. $("#productId").remove();
  39. $(".text-danger").remove();
  40. $(".form-group").removeClass('has-error').removeClass('has-success');
  41. $('.div-loading').removeClass('div-hide');
  42. $('.div-result').addClass('div-hide');
  43.  
  44. $.ajax({
  45. url: 'action.php',
  46. type: 'post',
  47. data: {productId: productId},
  48. dataType: 'json',
  49. success:function(response) {
  50. $('.div-loading').addClass('div-hide');
  51. $('.div-result').removeClass('div-hide');
  52.  
  53. $(".editProductFooter").append('<input type="hidden" name="productId" id="productId" value="'+response.product_id+'" />');
  54.  
  55. // product name
  56. $("#editProductName").val(response.product_name);
  57. // category name
  58. $("#editCategoryName").val(response.categories_id);
  59. // quantity
  60. $("#editProductQuantity").val(response.quantity);
  61. // product unit
  62. $("#editProductUnit").val(response.product_unit);
  63. // sales margin
  64. $("#editSalesMargin").val(response.sales_margin);
  65. // status
  66. $("#editProductStatus").val(response.status);
  67. // Get the product components count
  68. var totalComponents = response.total_components;
  69. // Loop for every component
  70. // Set the fields id that will contains the data
  71. // Fill the fields with data
  72. for (var x = 0; x<totalComponents; x++){
  73.  
  74. var idrawn = "#editRawName"+x.toString();
  75. var idrawq = "#editQuantity"+x.toString();
  76. var resri = "raw_id_"+x.toString();
  77. var resqu = "rp_quantity_"+x.toString();
  78. $(idrawn).val(response[resri]);
  79. $(idrawq).val(response[resqu]);
  80. }
  81.  
  82. if (totalComponents > 2) {
  83. var adro = totalComponents - 2;
  84. for (var y=0; y<adro; y++)
  85. { addRow(); }
  86. }
  87.  
  88. if (totalComponents > 2) {
  89. var adro = totalComponents - 2;
  90. for (var y=0; y<adro; y++)
  91. { eventFire(document.getElementById('addRowBtn'), 'click'); }
  92. }
  93.  
  94. function addRow() {
  95. $("#addRowBtn").button("loading");
  96. var tableLength = $("#rawTable tbody tr").length;
  97. var tableRow;
  98. var arrayNumber;
  99. var count;
  100.  
  101. if(tableLength > 0) {
  102. tableRow = $("#rawTable tbody tr:last").attr('id');
  103. arrayNumber = $("#rawTable tbody tr:last").attr('class');
  104. count = tableRow.substring(3);
  105. count = Number(count) + 1;
  106. arrayNumber = Number(arrayNumber) + 1;
  107. } else {
  108. // no table row
  109. count = 1;
  110. arrayNumber = 0;
  111. }
  112.  
  113. $.ajax({
  114. url: 'action1.php',
  115. type: 'post',
  116. dataType: 'json',
  117. success:function(response) {
  118. $("#addRowBtn").button("reset");
  119. var tr = '<tr id="row'+count+'" class="'+arrayNumber+'">'+
  120. '<td style="padding-left:20px;padding-right: 20px;">'+
  121. '<div class="form-group">'+
  122.  
  123. '<select class="form-control" name="rawName[]" id="rawName'+count+'" onchange="getRawData('+count+')" >'+
  124. '<option value="">~~SELECT~~</option>';
  125. $.each(response, function(index, value) {
  126. tr += '<option value="'+value[0]+'">'+value[1]+'</option>';
  127. });
  128. tr += '</select>'+
  129. '</div>'+
  130. '</td>'+
  131. '<td style="padding-left:20px;">'+
  132. '<div class="form-group">'+
  133. '<input type="number" name="quantity[]" id="quantity'+count+'" autocomplete="off" class="form-control" min="1" />'+
  134. '</div>'+
  135. '</td>'+
  136. '<td>'+
  137. '<button class="btn btn-default removeRawRowBtn" type="button" onclick="removeRawRow('+count+')"><i class="glyphicon glyphicon-trash"></i></button>'+
  138. '</td>'+
  139. '</tr>';
  140. if(tableLength > 0) {
  141. $("#rawTable tbody tr:last").after(tr);
  142. $("#totalComponents").remove();
  143. var comp = '<input type="hidden" name="totalComponents" id="totalComponents" value="'+count+'" />';
  144. } else {
  145. $("#rawTable tbody").append(tr);
  146. $("#totalComponents").remove();
  147. var comp = '<input type="hidden" name="totalComponents" id="totalComponents" value="'+tableLength+'" />';
  148. }
  149. $("#rawTable").after(comp);
  150. }
  151. });}
Add Comment
Please, Sign In to add comment