// This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. JavaScript code in this file should be added after the last require_* statement. // // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details // about supported directives. // //= require jquery //= require bootstrap //= require jquery_ujs //= require turbolinks //= require cable $(document).ready(function(){ $(".orders").on('click', function(){ var zone_name=$(this).find(".orders-table").text(); var receipt_no=$(this).find(".orders-receipt-no").text(); var unique_id=$(this).find(".orders-id").text(); var order_status=$(this).find(".orders-order-status").text().trim(); // Enable/Disable Button control_button(order_status); //for customer button if(unique_id.charAt(0) == 'S'){ $("#customer").removeAttr('disabled'); }else{ $("#customer").attr('disabled','disabled'); } var cashier=""; var receipt_date=""; var sub_total=0; var discount_amount=0; var tax_amount=0; var grand_total_amount=0; $("#order-title").text("ORDER DETAILS - " + zone_name); // clear order items $("#order-items-table").children("tbody").empty(); // AJAX call for order $.ajax({ type: "GET", url: "origami/" + unique_id, data: { 'id' : unique_id }, success:function(result){ for (i = 0; i < result.length; i++) { var data = JSON.stringify(result[i]); var parse_data = JSON.parse(data); // Receipt Header receipt_no = result[i].receipt_no; cashier = result[i].cashier_name; receipt_date = result[i].receipt_date; $("#receipt_no").text(receipt_no); $("#cashier").text(cashier==null?"":cashier); $("#receipt_date").text(receipt_date); //Receipt Charges sub_total += (parse_data.qty*parse_data.price); discount_amount = parse_data.discount_amount; tax_amount = parse_data.tax_amount; grand_total_amount = parse_data.grand_total_amount; $("#order-sub-total").text(sub_total); $("#order-food").text(''); $("#order-beverage").text(''); $("#order-discount").text(discount_amount); $("#order-Tax").text(tax_amount); $("#order-grand-total").text(grand_total_amount); // Ordered Items var order_items_rows = "" + "" + parse_data.item_name + "" + "" + parse_data.qty + "" + "" + parse_data.qty*parse_data.price + "" + ""; $("#order-items-table").children("tbody").append(order_items_rows); } } }); // End AJAX Call $('.orders').removeClass('selected-item'); $(this).addClass('selected-item'); }); // Bill Request $('#request_bills').click(function() { var order_id=$(".selected-item").find(".orders-id").text(); if(order_id!=""){ window.location.href = '/origami/request_bills/'+ order_id } else { alert("Please select an order!"); } return false; }); // Discount for Payment $('#discount').click(function() { var order_id=$(".selected-item").find(".orders-id").text(); if(order_id!=""){ window.location.href = '/origami/discount/'+ order_id } else { alert("Please select an order!"); } return false; }); // Pay Discount for Payment $("#pay-discount").on('click', function(){ var sale_id = $('#sale-id').text(); var sub_total = $('#order-sub-total').text(); var grand_total = $('#order-grand-total').text(); var discount_type = $('#discount-type').val(); var discount_value = $('#discount-amount').val(); var discount_amount = discount_value; // For Percentage Discount if(discount_type == 1){ discount_amount=(sub_total*discount_value)/100; } var params = {'sale_id': sale_id, 'grand_total' : grand_total, 'discount_type':discount_type, 'discount_value':discount_value, 'discount_amount':discount_amount}; $.ajax({ type: "POST", url: "/origami/discount", data: params, success:function(result){ } }); }); // Payment for Bill $('#pay-bill').click(function() { var sale_id=$(".selected-item").find(".orders-id").text(); if(sale_id!=""){ window.location.href = '/origami/sale/'+ sale_id + "/payment" } else { alert("Please select an order!"); } return false; }); $('#customer').click(function() { var sale_id=$(".selected-item").find(".orders-id").text(); window.location.href = '/crm/customers/'+ sale_id + "/assign_sale_id" return false; }); /* For Receipt - Calculate discount or tax */ $('.cashier_number').on('click', function(event){ if(event.handled !== true) { var original_value=0; original_value = $('#discount-amount').val(); var input_type = $(this).attr("data-type"); switch (input_type) { case 'num': var input_value = $(this).attr("data-value"); if (original_value == "0.0"){ $('#discount-amount').val(input_value); update_balance(); } else{ $('#discount-amount').val(original_value + '' + input_value); update_balance(); } break; case 'add': var input_value = $(this).attr("data-value"); amount = parseInt(input_value) + parseInt(original_value); $('#discount-amount').val(amount); update_balance(); break; case 'del' : var discount_text=$('#discount-amount').val(); $('#discount-amount').val(discount_text.substr(0,discount_text.length-1)); update_balance(); break; case 'clr': $('#discount-amount').val("0.0"); update_balance(); break; } event.handled = true; } else { return false; } }); }); /* Button Control by Status */ function control_button(order_status){ if(order_status=="billed"){ $("#request_bills").prop('disabled', true); $("#discount").prop('disabled', false); $("#pay-bill").prop('disabled', false); } else if(order_status=="new") { $("#request_bills").prop('disabled', false); $("#discount").prop('disabled', true); $("#pay-bill").prop('disabled', true); } } /* For Receipt - Update Balance */ function update_balance(){ var discount_type = $('#discount-type').val(); var discount_amount = $('#discount-amount').val(); var sub_total = $('#order-sub-total').text(); var tax = $('#order-Tax').text(); // For Percentage Discount if(discount_type == 1){ discount_amount=(sub_total*discount_amount)/100; } var total = (parseFloat(sub_total) + parseFloat(tax)) - discount_amount; $('#order-discount').text(discount_amount); $('#order-grand-total').text(total); }