Advertisement
freddy0512

der

Mar 31st, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.47 KB | None | 0 0
  1. //ini var kode buat di taruh di name=kode[] itu ku buat cara bodoh ku tapi gak jalan, value="<?php echo $id ?>"
  2. var kode=
  3.  
  4. var i=$('table tr').length;
  5. $(".addmore").on('click',function(){
  6. html = '<tr>';
  7. html += '<td><input class="case" type="checkbox"/></td>';
  8. html += '<td><input type="text" data-type="id_barang" name="itemNo[]" id="itemNo_'+i+'" class="form-control autocomplete_txt" autocomplete="off"> <input type="text" name="kode[]" id="kode_'+i+'" value="<?php echo $id ?>" > </td>';
  9. html += '<td><input type="text" data-type="nama_barang" name="itemName[]" id="itemName_'+i+'" class="form-control autocomplete_txt" autocomplete="off" readonly></td>';
  10. html += '<td><input type="text" name="StockName[]" id="StockName_'+i+'" class="form-control autocomplete_txt" autocomplete="off" readonly></td>';
  11. html += '<td><input type="text" name="price[]" id="price_'+i+'" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>';
  12. html += '<td><input type="text" name="quantity[]" id="quantity_'+i+'" class="form-control changesNo" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;"></td>';
  13. html += '<td><input type="text" name="total[]" id="total_'+i+'" class="form-control totalLinePrice" autocomplete="off" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;" readonly></td>';
  14. html += '</tr>';
  15. $('table').append(html);
  16. i++;
  17. });
  18.  
  19. //to check all checkboxes
  20. $(document).on('change','#check_all',function(){
  21. $('input[class=case]:checkbox').prop("checked", $(this).is(':checked'));
  22. });
  23.  
  24. //deletes the selected table rows
  25. $(".delete").on('click', function() {
  26. $('.case:checkbox:checked').parents("tr").remove();
  27. $('#check_all').prop("checked", false);
  28. calculateTotal();
  29. });
  30.  
  31. //autocomplete script
  32. $(document).on('focus','.autocomplete_txt',function(){
  33. type = $(this).data('type');
  34.  
  35. if(type =='id_barang' )autoTypeNo=0;
  36. if(type =='nama_barang' )autoTypeNo=1;
  37.  
  38. $(this).autocomplete({
  39. source: function( request, response ) {
  40. $.ajax({
  41. url : 'http://localhost/code_cipta/admin/product',
  42. dataType: "json",
  43. method: 'post',
  44. data: {
  45. name_startsWith: request.term,
  46. type: type
  47. },
  48. success: function( data ) {
  49. //alert ();
  50. response( $.map( data, function( item ) {
  51. var code = item.split("|");
  52. return {
  53. label: code[autoTypeNo],
  54. value: code[autoTypeNo],
  55. data : item
  56. }
  57. }));
  58. }
  59. });
  60. },
  61. autoFocus: true,
  62. minLength: 0,
  63. select: function( event, ui ) {
  64. var names = ui.item.data.split("|");
  65. id_arr = $(this).attr('id');
  66. id = id_arr.split("_");
  67.  
  68. //taruh di id item no
  69. $('#itemNo_'+id[1]).val(names[0]);
  70.  
  71. //taruh di id itemname
  72. $('#itemName_'+id[1]).val(names[1]);
  73.  
  74. $('#StockName_'+id[1]).val(names[2]);
  75.  
  76.  
  77.  
  78. //taruh di id quantity dengan array indeks 1
  79. $('#quantity_'+id[1]).val(1);
  80. //taruh di id harga dari database
  81. $('#price_'+id[1]).val(1);
  82. //taruh di id total
  83.  
  84.  
  85. quantity = $('#quantity_'+id[1]).val();
  86.  
  87. price = $('#price_'+id[1]).val();
  88.  
  89. $('#total_'+id[1]).val( quantity * price);
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. calculateTotal();
  97. }
  98. });
  99. });
  100.  
  101. //price change
  102. $(document).on('change keyup blur','.changesNo',function(){
  103. id_arr = $(this).attr('id');
  104. id = id_arr.split("_");
  105. quantity = $('#quantity_'+id[1]).val();
  106. price = $('#price_'+id[1]).val();
  107. if( quantity!='' && price !='' ) $('#total_'+id[1]).val( (parseFloat(price)*parseFloat(quantity)).toFixed(2) );
  108. calculateTotal();
  109. });
  110.  
  111. $(document).on('change keyup blur','#tax',function(){
  112. calculateTotal();
  113. });
  114.  
  115. //total price calculation
  116. function calculateTotal(){
  117. subTotal = 0 ; total = 0;
  118. $('.totalLinePrice').each(function(){
  119. if($(this).val() != '' )subTotal += parseFloat( $(this).val() );
  120. });
  121. $('#subTotal').val( subTotal.toFixed(2) );
  122. tax = $('#tax').val();
  123. if(tax != '' && typeof(tax) != "undefined" ){
  124. taxAmount = subTotal * ( parseFloat(tax) /100 );
  125. $('#taxAmount').val(taxAmount.toFixed(2));
  126. total = subTotal + taxAmount;
  127. }else{
  128. $('#taxAmount').val(0);
  129. total = subTotal;
  130. }
  131. $('#totalAftertax').val( total.toFixed(2) );
  132. calculateAmountDue();
  133. }
  134.  
  135. $(document).on('change keyup blur','#amountPaid',function(){
  136. calculateAmountDue();
  137. });
  138.  
  139. //due amount calculation
  140. function calculateAmountDue(){
  141. amountPaid = $('#amountPaid').val();
  142. total = $('#totalAftertax').val();
  143. if(amountPaid != '' && typeof(amountPaid) != "undefined" ){
  144. amountDue = parseFloat(total) - parseFloat( amountPaid );
  145. $('.amountDue').val( amountDue.toFixed(2) );
  146. }else{
  147. total = parseFloat(total).toFixed(2);
  148. $('.amountDue').val( total );
  149. }
  150. }
  151.  
  152.  
  153. //It restrict the non-numbers
  154. var specialKeys = new Array();
  155. specialKeys.push(8,46); //Backspace
  156. function IsNumeric(e) {
  157. var keyCode = e.which ? e.which : e.keyCode;
  158. console.log( keyCode );
  159. var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
  160. return ret;
  161. }
  162.  
  163. //datepicker
  164. $("#date").datepicker({
  165. dateFormat:"yy-mm-dd",
  166. changeMonth: true,
  167. changeYear: true
  168. });
  169.  
  170. $("#tanggal").datepicker({
  171. dateFormat:"yy-mm-dd",
  172. changeMonth: true,
  173. changeYear: true
  174. });
  175.  
  176. $("#kode_suplier").autocomplete({
  177. source: "http://localhost/code_cipta/admin/pembelian/getsuplier" // path to the get_birds method
  178. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement