update second display
This commit is contained in:
112
app/assets/javascripts/channels/second_display_view.js
Normal file
112
app/assets/javascripts/channels/second_display_view.js
Normal file
@@ -0,0 +1,112 @@
|
||||
App.checkin = App.cable.subscriptions.create('SecondDisplayViewChannel', {
|
||||
// App.messages = App.cable.subscriptions.create('MessagesChannel', {
|
||||
|
||||
connected: function() {},
|
||||
|
||||
disconnected: function() {},
|
||||
|
||||
received: function(data) {
|
||||
var items = data.data;
|
||||
var tax = data.tax_profiles;
|
||||
var status= data.status
|
||||
if (status == "reload") {
|
||||
window.location.reload();
|
||||
}
|
||||
$('#second_display_slider').addClass("hidden")
|
||||
$('#second_display_items').removeClass("hidden")
|
||||
// append items
|
||||
for(var i in items) {
|
||||
qty = parseInt(items[i].qty);
|
||||
append = 0;
|
||||
price = items[i].price;
|
||||
|
||||
instance_name = items[i].instance;
|
||||
if (instance_name == "undefined"){
|
||||
instance = '';
|
||||
}else{
|
||||
instance = "("+items[i].instance+")";
|
||||
}
|
||||
|
||||
var rowCount = $('.second_display_items tbody tr').length+1;
|
||||
var item_row = $('.second_display_items tbody tr');
|
||||
|
||||
$(item_row).each(function(j){
|
||||
var item_code = $(item_row[j]).attr('data-code');
|
||||
var instance_code = $(item_row[j]).attr('data-instance-code');
|
||||
|
||||
if (item_code == items[i].item_code && instance_code == items[i].instance_code) {
|
||||
if (qty > 1) {
|
||||
qty = parseInt($(item_row[j]).children('#item_qty').text()) + qty;
|
||||
}else{
|
||||
qty = parseInt($(item_row[j]).children('#item_qty').text()) + 1;
|
||||
}
|
||||
|
||||
$(item_row[j]).children('#item_qty').text(qty);
|
||||
parseFloat($(item_row[j]).children('#item_price').text(parseFloat(price*qty).toFixed(2)));
|
||||
append =1;
|
||||
}else{
|
||||
if (qty > 1) {
|
||||
qty = qty;
|
||||
}else{
|
||||
qty = 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (append===0) {
|
||||
row ="<tr class='item_box' data-price ='"
|
||||
+price+ "' 'data-instance ='"
|
||||
+instance+ "' data-code='"+items[i].item_code+"' data-instance-code='"
|
||||
+items[i].instance_code+"' data-attributes='"
|
||||
+items[i].attributes+"' data-options ='"
|
||||
+items[i].options+"' data-row ='"+rowCount+ "'>"
|
||||
+'<td class="item-cell-no">'+rowCount+'</td>'
|
||||
+'<td class="item-cell-name" id="item_name" >' + items[i].name+ ' ' + instance +'</td>'
|
||||
+'<td class="item-cell-qty" id="item_qty">' + qty + '</td>'
|
||||
+'<td class="item-cell-price" id="item_price">'
|
||||
+ parseFloat(price).toFixed(2)
|
||||
+'</td>'
|
||||
+'</tr>';
|
||||
$(".second_display_items tbody").append(row);
|
||||
|
||||
}
|
||||
}
|
||||
//end apend items
|
||||
var total_price = 0;
|
||||
var taxable_amount = 0;
|
||||
var total_discount = 0
|
||||
var total_tax_amount = 0
|
||||
var item_row = $('.second_display_items tbody tr');
|
||||
//calculate Sub Total
|
||||
$(item_row).each(function(i){
|
||||
var unit_price = parseFloat($(item_row[i]).attr('data-price'));
|
||||
var qty = parseFloat($(item_row[i]).children('#item_qty').text());
|
||||
total_price += qty*unit_price;
|
||||
});
|
||||
//calculate Tax Amount
|
||||
for(var i in tax) {
|
||||
// substract , to give after discount
|
||||
var total_tax = total_price - total_discount
|
||||
// include or execulive
|
||||
if (tax[i].inclusive){
|
||||
rate = tax[i].rate
|
||||
divided_value = (100 + rate)/rate
|
||||
total_tax_amount = total_tax_amount + (total_tax / divided_value)
|
||||
}else{
|
||||
total_tax_amount = total_tax_amount + (total_tax * tax[i].rate / 100)
|
||||
}
|
||||
}
|
||||
//end calculate Tax amount
|
||||
var fixed_total_price = parseFloat(total_price).toFixed(2);
|
||||
var fixed_taxable_amount = parseFloat(total_tax_amount).toFixed(2);
|
||||
var fixed_grand_total = parseFloat(total_price + total_tax_amount).toFixed(2);
|
||||
|
||||
$('#s_sub_total').empty();
|
||||
$('#s_sub_total').append(fixed_total_price);
|
||||
$('#s_tatal_tax').empty();
|
||||
$('#s_tatal_tax').append(fixed_taxable_amount);
|
||||
$('#s_grand_total').empty();
|
||||
$('#s_grand_total').append(fixed_grand_total);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user