Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///ini baris tambahkan otomatisnya
- var i=$('table tr').length;
- $(".addmore").on('click',function(){
- html = '<tr>';
- html += '<td><input class="case" type="checkbox"/></td>';
- html += '<td><input type="text" data-type="id_barang" name="itemNo[]" id="itemNo_'+i+'" class="form-control autocomplete_txt" autocomplete="off"> <input type="text" data-type="kode" name="kode[]" id="kode_'+i+'" > </td>';
- html += '<td><input type="text" data-type="nama_barang" name="itemName[]" id="itemName_'+i+'" class="form-control autocomplete_txt" autocomplete="off" readonly></td>';
- html += '<td><input type="text" name="StockName[]" id="StockName_'+i+'" class="form-control autocomplete_txt" autocomplete="off" readonly></td>';
- 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>';
- 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>';
- 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>';
- html += '</tr>';
- $('table').append(html);
- i++;
- });
- //to check all checkboxes
- $(document).on('change','#check_all',function(){
- $('input[class=case]:checkbox').prop("checked", $(this).is(':checked'));
- });
- //deletes the selected table rows
- $(".delete").on('click', function() {
- $('.case:checkbox:checked').parents("tr").remove();
- $('#check_all').prop("checked", false);
- calculateTotal();
- });
- //autocomplete script
- $(document).on('focus','.autocomplete_txt',function(){
- type = $(this).data('type');
- if(type =='id_barang' )autoTypeNo=0;
- if(type =='nama_barang' )autoTypeNo=1;
- $(this).autocomplete({
- source: function( request, response ) {
- $.ajax({
- url : 'http://localhost/code_cipta/admin/product',
- dataType: "json",
- method: 'post',
- data: {
- name_startsWith: request.term,
- type: type
- },
- success: function( data ) {
- //alert ();
- response( $.map( data, function( item ) {
- var code = item.split("|");
- return {
- label: code[autoTypeNo],
- value: code[autoTypeNo],
- data : item
- }
- }));
- }
- });
- },
- autoFocus: true,
- minLength: 0,
- select: function( event, ui ) {
- var names = ui.item.data.split("|");
- id_arr = $(this).attr('id');
- id = id_arr.split("_");
- //taruh di id item no
- $('#itemNo_'+id[1]).val(names[0]);
- //taruh di id itemname
- $('#itemName_'+id[1]).val(names[1]);
- $('#StockName_'+id[1]).val(names[2]);
- //taruh di id quantity dengan array indeks 1
- $('#quantity_'+id[1]).val(1);
- //taruh di id harga dari database
- $('#price_'+id[1]).val(1);
- //taruh di id total
- quantity = $('#quantity_'+id[1]).val();
- price = $('#price_'+id[1]).val();
- $('#total_'+id[1]).val( quantity * price);
- calculateTotal();
- }
- });
- });
- //price change
- $(document).on('change keyup blur','.changesNo',function(){
- id_arr = $(this).attr('id');
- id = id_arr.split("_");
- quantity = $('#quantity_'+id[1]).val();
- price = $('#price_'+id[1]).val();
- if( quantity!='' && price !='' ) $('#total_'+id[1]).val( (parseFloat(price)*parseFloat(quantity)).toFixed(2) );
- calculateTotal();
- });
- $(document).on('change keyup blur','#tax',function(){
- calculateTotal();
- });
- //total price calculation
- function calculateTotal(){
- subTotal = 0 ; total = 0;
- $('.totalLinePrice').each(function(){
- if($(this).val() != '' )subTotal += parseFloat( $(this).val() );
- });
- $('#subTotal').val( subTotal.toFixed(2) );
- tax = $('#tax').val();
- if(tax != '' && typeof(tax) != "undefined" ){
- taxAmount = subTotal * ( parseFloat(tax) /100 );
- $('#taxAmount').val(taxAmount.toFixed(2));
- total = subTotal + taxAmount;
- }else{
- $('#taxAmount').val(0);
- total = subTotal;
- }
- $('#totalAftertax').val( total.toFixed(2) );
- calculateAmountDue();
- }
- $(document).on('change keyup blur','#amountPaid',function(){
- calculateAmountDue();
- });
- //due amount calculation
- function calculateAmountDue(){
- amountPaid = $('#amountPaid').val();
- total = $('#totalAftertax').val();
- if(amountPaid != '' && typeof(amountPaid) != "undefined" ){
- amountDue = parseFloat(total) - parseFloat( amountPaid );
- $('.amountDue').val( amountDue.toFixed(2) );
- }else{
- total = parseFloat(total).toFixed(2);
- $('.amountDue').val( total );
- }
- }
- //It restrict the non-numbers
- var specialKeys = new Array();
- specialKeys.push(8,46); //Backspace
- function IsNumeric(e) {
- var keyCode = e.which ? e.which : e.keyCode;
- console.log( keyCode );
- var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
- return ret;
- }
- //datepicker
- $("#date").datepicker({
- dateFormat:"yy-mm-dd",
- changeMonth: true,
- changeYear: true
- });
- $("#tanggal").datepicker({
- dateFormat:"yy-mm-dd",
- changeMonth: true,
- changeYear: true
- });
- $("#kode_suplier").autocomplete({
- source: "http://localhost/code_cipta/admin/pembelian/getsuplier" // path to the get_birds method
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement