Advertisement
freddy0512

wewkwkwkw

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