discount updated
This commit is contained in:
@@ -10,50 +10,89 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
@accounts = Account.all
|
@accounts = Account.all
|
||||||
end
|
end
|
||||||
|
|
||||||
#discount for selected order
|
#discount page show from origami index with selected order
|
||||||
def create
|
def create
|
||||||
sale_id = params[:sale_id]
|
sale_id = params[:sale_id]
|
||||||
sale_item_id = params[:sale_item_id]
|
discount_items = JSON.parse(params[:discount_items])
|
||||||
discount_type = params[:discount_type]
|
overall_discount = params[:overall_discount]
|
||||||
discount_value = params[:discount_value]
|
sub_total = params[:sub_total]
|
||||||
discount_amount = params[:discount_amount]
|
|
||||||
grand_total = params[:grand_total]
|
|
||||||
product_name = "Overall Discount"
|
|
||||||
|
|
||||||
if discount_type == 0
|
if Sale.exists?(sale_id)
|
||||||
remark="Discount " + discount_amount + " as net"
|
sale = Sale.find(sale_id)
|
||||||
else
|
sale.total_discount = overall_discount.to_f
|
||||||
remark="Discount " + discount_amount + " as percentage"
|
sale.total_amount = sub_total
|
||||||
end
|
sale.grand_total = (sub_total - overall_discount.to_f) + sale.total_tax;
|
||||||
|
|
||||||
#update discount for sale
|
if discount_items.length > 0
|
||||||
sale = Sale.find(sale_id)
|
#save sale item for discount
|
||||||
sale.total_discount = sale.total_discount + discount_amount.to_f
|
discount_items.each do |di|
|
||||||
sale.grand_total = grand_total
|
puts di
|
||||||
sale.save
|
origin_sale_item = SaleItem.find(di["id"])
|
||||||
|
sale_item = SaleItem.new
|
||||||
|
|
||||||
#save sale item for discount
|
sale_item.sale_id = sale_id
|
||||||
if sale_item_id != nil
|
sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id
|
||||||
origin_sale_item = SaleItem.find(sale_item_id)
|
sale_item.product_name = di["name"]
|
||||||
product_name = origin_sale_item.product_name + "-Disocunt"
|
sale_item.remark = "Discount"
|
||||||
|
|
||||||
|
sale_item.qty = 1
|
||||||
|
sale_item.unit_price = di["price"]
|
||||||
|
sale_item.taxable_price = di["price"]
|
||||||
|
sale_item.is_taxable = 0
|
||||||
|
|
||||||
|
sale_item.price = di["price"]
|
||||||
|
sale_item.save
|
||||||
|
end
|
||||||
|
|
||||||
|
sale.save
|
||||||
|
end
|
||||||
end
|
end
|
||||||
sale_item = SaleItem.new
|
|
||||||
|
|
||||||
#pull
|
|
||||||
sale_item.sale_id = sale_id
|
|
||||||
sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id
|
|
||||||
sale_item.product_name = product_name
|
|
||||||
sale_item.remark = remark
|
|
||||||
|
|
||||||
sale_item.qty = 1
|
|
||||||
sale_item.unit_price = (0-discount_amount.to_f)
|
|
||||||
sale_item.taxable_price = discount_amount
|
|
||||||
sale_item.is_taxable = 0
|
|
||||||
|
|
||||||
sale_item.price = sale_item.qty * sale_item.unit_price
|
|
||||||
sale_item.save
|
|
||||||
|
|
||||||
redirect_to origami_path(sale_id)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#discount for selected order
|
||||||
|
# def create
|
||||||
|
# sale_id = params[:sale_id]
|
||||||
|
# sale_item_id = params[:sale_item_id]
|
||||||
|
# discount_type = params[:discount_type]
|
||||||
|
# discount_value = params[:discount_value]
|
||||||
|
# discount_amount = params[:discount_amount]
|
||||||
|
# grand_total = params[:grand_total]
|
||||||
|
# product_name = "Overall Discount"
|
||||||
|
|
||||||
|
# if discount_type == 0
|
||||||
|
# remark="Discount " + discount_amount + " as net"
|
||||||
|
# else
|
||||||
|
# remark="Discount " + discount_amount + " as percentage"
|
||||||
|
# end
|
||||||
|
|
||||||
|
# #update discount for sale
|
||||||
|
# sale = Sale.find(sale_id)
|
||||||
|
# sale.total_discount = sale.total_discount + discount_amount.to_f
|
||||||
|
# sale.grand_total = grand_total
|
||||||
|
# sale.save
|
||||||
|
|
||||||
|
# #save sale item for discount
|
||||||
|
# if sale_item_id != nil
|
||||||
|
# origin_sale_item = SaleItem.find(sale_item_id)
|
||||||
|
# product_name = origin_sale_item.product_name + "-Disocunt"
|
||||||
|
# end
|
||||||
|
# sale_item = SaleItem.new
|
||||||
|
|
||||||
|
# #pull
|
||||||
|
# sale_item.sale_id = sale_id
|
||||||
|
# sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id
|
||||||
|
# sale_item.product_name = product_name
|
||||||
|
# sale_item.remark = remark
|
||||||
|
|
||||||
|
# sale_item.qty = 1
|
||||||
|
# sale_item.unit_price = (0-discount_amount.to_f)
|
||||||
|
# sale_item.taxable_price = discount_amount
|
||||||
|
# sale_item.is_taxable = 0
|
||||||
|
|
||||||
|
# sale_item.price = sale_item.qty * sale_item.unit_price
|
||||||
|
# sale_item.save
|
||||||
|
|
||||||
|
# redirect_to origami_path(sale_id)
|
||||||
|
# end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ class MenuItem < ApplicationRecord
|
|||||||
if (!mt_instance.nil?)
|
if (!mt_instance.nil?)
|
||||||
menu_item = MenuItem.find(mt_instance.menu_item_id)
|
menu_item = MenuItem.find(mt_instance.menu_item_id)
|
||||||
menu_item_hash[:type] = menu_item.type
|
menu_item_hash[:type] = menu_item.type
|
||||||
|
menu_item_hash[:account_id] = menu_item.account_id
|
||||||
menu_item_hash[:item_code] = menu_item.item_code
|
menu_item_hash[:item_code] = menu_item.item_code
|
||||||
menu_item_hash[:item_instance_code] = mt_instance.item_instance_code
|
menu_item_hash[:item_instance_code] = mt_instance.item_instance_code
|
||||||
menu_item_hash[:name] = menu_item.name.to_s + " - " + mt_instance.item_instance_name.to_s
|
menu_item_hash[:name] = menu_item.name.to_s + " - " + mt_instance.item_instance_name.to_s
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ class Order < ApplicationRecord
|
|||||||
set_order_items
|
set_order_items
|
||||||
end
|
end
|
||||||
|
|
||||||
OrderItem.processs_item(menu_item[:item_code], menu_item[:name], menu_item[:account_id]
|
OrderItem.processs_item(menu_item[:item_code], menu_item[:name], menu_item[:account_id],
|
||||||
item[:quantity],menu_item[:price], item[:options], set_order_items, self.id,
|
item[:quantity],menu_item[:price], item[:options], set_order_items, self.id,
|
||||||
self.employee_name)
|
self.employee_name)
|
||||||
|
|
||||||
|
|||||||
@@ -30,8 +30,9 @@
|
|||||||
<% sub_total = 0 %>
|
<% sub_total = 0 %>
|
||||||
<% @sale_data.sale_items.each do |sale_item| %>
|
<% @sale_data.sale_items.each do |sale_item| %>
|
||||||
<% sub_total += sale_item.qty*sale_item.unit_price%>
|
<% sub_total += sale_item.qty*sale_item.unit_price%>
|
||||||
<tr class="discount-item-row" id=<%= sale_item.sale_item_id %> >
|
<tr class="item-row" id=<%= sale_item.sale_item_id %> >
|
||||||
<td style="width:60%; text-align:left">
|
<td style="width:60%; text-align:left">
|
||||||
|
<span id="item-account-type" class="hidden"><%=sale_item.account_id%></span>
|
||||||
<span id="item-name-price"><%=sale_item.product_name%>@<%=sale_item.unit_price%></span>
|
<span id="item-name-price"><%=sale_item.product_name%>@<%=sale_item.unit_price%></span>
|
||||||
</td>
|
</td>
|
||||||
<td style="width:20%; text-align:right">
|
<td style="width:20%; text-align:right">
|
||||||
@@ -61,7 +62,7 @@
|
|||||||
</tr> -->
|
</tr> -->
|
||||||
<tr>
|
<tr>
|
||||||
<td class="charges-name"><strong>Discount:</strong></td>
|
<td class="charges-name"><strong>Discount:</strong></td>
|
||||||
<td class="item-attr"><strong id="order-discount">(<%=@sale_data.total_discount rescue 0%>)</strong></td>
|
<td class="item-attr">(<strong id="order-discount"><%=@sale_data.total_discount rescue 0%></strong>)</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="hidden">
|
<tr class="hidden">
|
||||||
<td class="charges-name"><strong>Tax:</strong></td>
|
<td class="charges-name"><strong>Tax:</strong></td>
|
||||||
@@ -190,11 +191,11 @@ $(document).ready(function(){
|
|||||||
var input_value = $(this).attr("data-value");
|
var input_value = $(this).attr("data-value");
|
||||||
if (original_value == "0.0"){
|
if (original_value == "0.0"){
|
||||||
$('#discount-amount').val(input_value);
|
$('#discount-amount').val(input_value);
|
||||||
update_balance();
|
// update_balance();
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$('#discount-amount').val(original_value + '' + input_value);
|
$('#discount-amount').val(original_value + '' + input_value);
|
||||||
update_balance();
|
// update_balance();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -202,18 +203,18 @@ $(document).ready(function(){
|
|||||||
var input_value = $(this).attr("data-value");
|
var input_value = $(this).attr("data-value");
|
||||||
amount = parseInt(input_value);
|
amount = parseInt(input_value);
|
||||||
$('#discount-amount').val(amount);
|
$('#discount-amount').val(amount);
|
||||||
update_balance();
|
// update_balance();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'del' :
|
case 'del' :
|
||||||
var discount_text=$('#discount-amount').val();
|
var discount_text=$('#discount-amount').val();
|
||||||
$('#discount-amount').val(discount_text.substr(0,discount_text.length-1));
|
$('#discount-amount').val(discount_text.substr(0,discount_text.length-1));
|
||||||
update_balance();
|
// update_balance();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'clr':
|
case 'clr':
|
||||||
$('#discount-amount').val("0.0");
|
$('#discount-amount').val("0.0");
|
||||||
update_balance();
|
// update_balance();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
event.handled = true;
|
event.handled = true;
|
||||||
@@ -223,7 +224,7 @@ $(document).ready(function(){
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Select Sale Item
|
// Select Sale Item
|
||||||
$('.discount-item-row').on('click',function(){
|
$('.item-row').on('click',function(){
|
||||||
if($(this).hasClass('selected-item') == true){
|
if($(this).hasClass('selected-item') == true){
|
||||||
$(this).removeClass('selected-item');
|
$(this).removeClass('selected-item');
|
||||||
}
|
}
|
||||||
@@ -255,45 +256,62 @@ $(document).ready(function(){
|
|||||||
// Selected Account
|
// Selected Account
|
||||||
var account_types = get_selected_account_types();
|
var account_types = get_selected_account_types();
|
||||||
|
|
||||||
calculate_item_discount(sale_items, account_types);
|
if(sale_items.length == 0 && account_types.length == 0){
|
||||||
|
calculate_overall_discount(0, discount_value);
|
||||||
console.log(sale_items);
|
}
|
||||||
|
else {
|
||||||
// var sub_total = $('#order-sub-total').text();
|
calculate_item_discount(0, discount_value, sale_items, account_types);
|
||||||
// var grand_total = $('#order-grand-total').text();
|
}
|
||||||
// var discount_value = $('#discount-amount').val();
|
|
||||||
// var discount_amount = discount_value;
|
|
||||||
// var ajax_url = "/origami/" + sale_id + "/discount";
|
|
||||||
|
|
||||||
// if(sale_item_id != null){
|
|
||||||
// ajax_url = "/origami/" + sale_item_id + "/discount";
|
|
||||||
// sub_total = $("#"+sale_item_id).children().find("#item-total-price").text();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// // For Percentage Discount
|
|
||||||
// if(discount_type == 1){
|
|
||||||
// discount_amount=(sub_total*discount_value)/100;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// var params = {'sale_id': sale_id, 'sale_item_id': sale_item_id, 'grand_total' : grand_total, 'discount_type':discount_type, 'discount_value':discount_value, 'discount_amount':discount_amount};
|
|
||||||
// $.ajax({
|
|
||||||
// type: "POST",
|
|
||||||
// url: ajax_url,
|
|
||||||
// data: params,
|
|
||||||
// success:function(result){ }
|
|
||||||
// });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Calculate Percentage Discount for Payment
|
// Calculate Percentage Discount for Payment
|
||||||
$("#percentage").on('click', function(e){
|
$("#percentage").on('click', function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var sale_id = $('#sale-id').text();
|
var sale_id = $('#sale-id').text();
|
||||||
var sale_item_id = $('.selected-item').attr('id').substr(0,16);
|
|
||||||
var sub_total = $('#order-sub-total').text();
|
|
||||||
var grand_total = $('#order-grand-total').text();
|
|
||||||
var discount_value = $('#discount-amount').val();
|
var discount_value = $('#discount-amount').val();
|
||||||
var discount_amount = discount_value;
|
|
||||||
var ajax_url = "/origami/" + sale_id + "/discount";
|
var ajax_url = "/origami/" + sale_id + "/discount";
|
||||||
|
|
||||||
|
// Selected Items
|
||||||
|
var sale_items = get_selected_sale_items();
|
||||||
|
|
||||||
|
// Selected Account
|
||||||
|
var account_types = get_selected_account_types();
|
||||||
|
|
||||||
|
if(sale_items.length == 0 && account_types.length == 0){
|
||||||
|
calculate_overall_discount(1, discount_value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
calculate_item_discount(1, discount_value, sale_items, account_types);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Pay Discount
|
||||||
|
// Pay Discount for Payment
|
||||||
|
$("#pay-discount").on('click', function(e){
|
||||||
|
e.preventDefault();
|
||||||
|
var sale_id = $('#sale-id').text();
|
||||||
|
var discount_items = JSON.stringify(get_discount_item_rows());
|
||||||
|
var overall_discount = $("#order-discount").text();
|
||||||
|
var sub_total = $('#order-sub-total').text();
|
||||||
|
// var sale_item_id = $('.selected-item').attr('id').substr(0,16);
|
||||||
|
// 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;
|
||||||
|
var ajax_url = "/origami/" + sale_id + "/discount";
|
||||||
|
|
||||||
|
var params = { 'sale_id': sale_id, 'sub_total': sub_total, 'discount_items': discount_items, 'overall_discount': overall_discount };
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
url: ajax_url,
|
||||||
|
data: params,
|
||||||
|
success:function(result){
|
||||||
|
alert("Successfully Discount!");
|
||||||
|
window.history.back();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -304,21 +322,52 @@ function update_balance(){
|
|||||||
var tax = $('#order-Tax').text();
|
var tax = $('#order-Tax').text();
|
||||||
|
|
||||||
// For Percentage Discount
|
// For Percentage Discount
|
||||||
if(discount_type == 1){
|
// if(discount_type == 1){
|
||||||
discount_amount=(sub_total*discount_amount)/100;
|
// discount_amount=(sub_total*discount_amount)/100;
|
||||||
}
|
// }
|
||||||
|
|
||||||
var total = (parseFloat(sub_total) + parseFloat(tax)) - discount_amount;
|
var total = (parseFloat(sub_total) + parseFloat(tax)) - discount_amount;
|
||||||
$('#order-discount').text(discount_amount);
|
$('#order-discount').text(discount_amount);
|
||||||
$('#order-grand-total').text(total);
|
$('#order-grand-total').text(total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get Item rows but not discount*/
|
||||||
|
function get_item_rows(){
|
||||||
|
var sale_items = [];
|
||||||
|
$('.item-row').not('.discount-item-row').each(function(i){
|
||||||
|
var sale_item = {};
|
||||||
|
sale_item.id = $(this).attr('id').substr(0,16);
|
||||||
|
sale_item.name = $(this).find('#item-name-price').text().split('@')[0];
|
||||||
|
sale_item.account_id = $(this).find('#item-account-type').text();
|
||||||
|
sale_item.price = $(this).find('#item-total-price').text();
|
||||||
|
sale_items.push(sale_item);
|
||||||
|
});
|
||||||
|
return sale_items;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Get discount Item rows */
|
||||||
|
function get_discount_item_rows(){
|
||||||
|
var sale_items = [];
|
||||||
|
$('.discount-item-row').each(function(i){
|
||||||
|
var sale_item = {};
|
||||||
|
sale_item.id = $(this).attr('id');
|
||||||
|
sale_item.name = $(this).find('#item-name-price').text();
|
||||||
|
sale_item.account_id = $(this).find('#item_account_type').text();
|
||||||
|
sale_item.price = $(this).find('#item-total-price').text();
|
||||||
|
sale_items.push(sale_item);
|
||||||
|
});
|
||||||
|
return sale_items;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Get Selected Sale Item's ID and Price */
|
/* Get Selected Sale Item's ID and Price */
|
||||||
function get_selected_sale_items(){
|
function get_selected_sale_items(){
|
||||||
var sale_items = [];
|
var sale_items = [];
|
||||||
$('.selected-item').each(function(i){
|
$('.selected-item').each(function(i){
|
||||||
var sale_item = {};
|
var sale_item = {};
|
||||||
sale_item.id = $(this).attr('id').substr(0,16);
|
sale_item.id = $(this).attr('id').substr(0,16);
|
||||||
|
sale_item.name = $(this).find('#item-name-price').text().split('@')[0];
|
||||||
|
sale_item.account_id = $(this).find('#item-account-type').text();
|
||||||
sale_item.price = $(this).find('#item-total-price').text();
|
sale_item.price = $(this).find('#item-total-price').text();
|
||||||
sale_items.push(sale_item);
|
sale_items.push(sale_item);
|
||||||
});
|
});
|
||||||
@@ -338,4 +387,164 @@ function get_selected_account_types(){
|
|||||||
return account_types;
|
return account_types;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Calculate Overall Discount*/
|
||||||
|
function calculate_overall_discount(type, amount){
|
||||||
|
var origin_sub_total = parseFloat($("#order-sub-total").text());
|
||||||
|
var dis_amount = 0;
|
||||||
|
var sub_total = 0;
|
||||||
|
var total_discount = 0;
|
||||||
|
|
||||||
|
// For Net Pay
|
||||||
|
if(type == 0){
|
||||||
|
total_discount = amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For Percentage Pay
|
||||||
|
if(type == 1){
|
||||||
|
if(amount > 100 ){
|
||||||
|
aler("Percentage Value over 100!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
total_discount = (origin_sub_total * amount)/100;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#order-discount").text(total_discount);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Calculate Items Discount*/
|
||||||
|
function calculate_item_discount(type, amount, sale_items, account_types){
|
||||||
|
var origin_sub_total = parseFloat($("#order-sub-total").text());
|
||||||
|
var dis_amount = 0;
|
||||||
|
var sub_total = 0;
|
||||||
|
var total_discount = 0;
|
||||||
|
// For Net Pay
|
||||||
|
if(type == 0){
|
||||||
|
dis_amount = (0 - amount);
|
||||||
|
if(sale_items.length > 0){
|
||||||
|
for(var i=0;i < sale_items.length;i++){
|
||||||
|
if(account_types.length > 0){
|
||||||
|
for(var j=0; j < account_types.length; j++){
|
||||||
|
if(sale_items[i].account_id != account_types[j].id){
|
||||||
|
// Discount Items
|
||||||
|
var discount_item_row = item_row_template(type, sale_items[i], dis_amount, amount);
|
||||||
|
$("#order-items-table tbody").append(discount_item_row);
|
||||||
|
total_discount = total_discount + amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
|
||||||
|
$("#order-items-table tbody").append(discount_item_row);
|
||||||
|
total_discount = total_discount + amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(account_types.length > 0){
|
||||||
|
var item_rows=get_item_rows();
|
||||||
|
if(item_rows.length > 0){
|
||||||
|
for(var k=0; k < item_rows.length; k++){
|
||||||
|
for(var j=0; j < account_types.length; j++){
|
||||||
|
if(item_rows[k].account_id == account_types[j].id){
|
||||||
|
// Discount Items
|
||||||
|
var discount_item_row = item_row_template(type, item_rows[k], dis_amount, amount);
|
||||||
|
$("#order-items-table tbody").append(discount_item_row);
|
||||||
|
total_discount = total_discount + amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alert("No Items!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub_total = origin_sub_total - total_discount;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For Percentage Pay
|
||||||
|
if(type == 1){
|
||||||
|
if(amount > 100 ){
|
||||||
|
aler("Percentage Value over 100!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check sale items exists
|
||||||
|
if(sale_items.length > 0){
|
||||||
|
for(var i=0;i < sale_items.length;i++){
|
||||||
|
if(account_types.length > 0){
|
||||||
|
for(var j=0; j < account_types.length; j++){
|
||||||
|
if(sale_items[i].account_id != account_types[j].id){
|
||||||
|
// Discount Items
|
||||||
|
dis_amount = 0 - ((sale_items[i].price * amount)/100);
|
||||||
|
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
|
||||||
|
$("#order-items-table tbody").append(discount_item_row);
|
||||||
|
total_discount = total_discount + dis_amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
dis_amount = 0 - ((sale_items[i].price * amount)/100);
|
||||||
|
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
|
||||||
|
$("#order-items-table tbody").append(discount_item_row);
|
||||||
|
total_discount = total_discount + dis_amount;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check account types exists
|
||||||
|
if(account_types.length > 0){
|
||||||
|
var item_rows=get_item_rows();
|
||||||
|
console.log(account_types);
|
||||||
|
if(item_rows.length > 0){
|
||||||
|
for(var k=0; k < item_rows.length; k++){
|
||||||
|
for(var j=0; j < account_types.length; j++){
|
||||||
|
if(item_rows[k].account_id == account_types[j].id){
|
||||||
|
// Discount Items
|
||||||
|
dis_amount = 0 - ((item_rows[k].price * amount)/100);
|
||||||
|
var discount_item_row = item_row_template(type, item_rows[k], dis_amount, amount);
|
||||||
|
$("#order-items-table tbody").append(discount_item_row);
|
||||||
|
total_discount = total_discount + dis_amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alert("No Items!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub_total = origin_sub_total + total_discount;
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#order-sub-total").text(sub_total);
|
||||||
|
}
|
||||||
|
|
||||||
|
function item_row_template(type, item, discount_amount, amount){
|
||||||
|
var dis_str = "-discount";
|
||||||
|
if(type == 1){
|
||||||
|
dis_str = dis_str + "(" + amount + "%)"
|
||||||
|
}
|
||||||
|
var discount_item_row = "<tr class='item-row discount-item-row' id='" + item.id + "'>" +
|
||||||
|
"<td style='width: 60%; text-align: left;'>" +
|
||||||
|
"<span id='item_account_type' class='hidden'>" +
|
||||||
|
item.account_id +
|
||||||
|
"</span>" +
|
||||||
|
"<span id='item-name-price'>" +
|
||||||
|
item.name + dis_str +
|
||||||
|
"</span>" +
|
||||||
|
"</td>" +
|
||||||
|
"<td style='width: 20%; text-align: right;'>" +
|
||||||
|
"<span id='item-qty'>1</span>" +
|
||||||
|
"</td>" +
|
||||||
|
"<td style='width: 20%; text-align: right;'>" +
|
||||||
|
"<span id='item-total-price'>" +
|
||||||
|
discount_amount +
|
||||||
|
"</span>" +
|
||||||
|
"</td>" +
|
||||||
|
"</tr>";
|
||||||
|
return discount_item_row;
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class CreateOrderItems < ActiveRecord::Migration[5.1]
|
|||||||
t.string :item_order_by #person who order this
|
t.string :item_order_by #person who order this
|
||||||
t.string :item_code, :null => false
|
t.string :item_code, :null => false
|
||||||
t.string :item_name, :null => false
|
t.string :item_name, :null => false
|
||||||
t.integer :account, :limit => 8, :null => false, :default => 1
|
t.integer :account_id, :limit => 8, :null => false, :default => 1
|
||||||
t.decimal :qty, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
t.decimal :qty, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
||||||
t.decimal :price, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
t.decimal :price, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
||||||
t.string :remark
|
t.string :remark
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class CreateSaleItems < ActiveRecord::Migration[5.1]
|
|||||||
t.string :sale_id, foreign_key: true, :limit => 16
|
t.string :sale_id, foreign_key: true, :limit => 16
|
||||||
t.string :product_code, :null => false
|
t.string :product_code, :null => false
|
||||||
t.string :product_name, :null => false
|
t.string :product_name, :null => false
|
||||||
t.integer :account, :limit => 8, :null => false, :default => 1
|
t.integer :account_id, :limit => 8, :null => false, :default => 1
|
||||||
t.string :remark
|
t.string :remark
|
||||||
t.decimal :qty, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
t.decimal :qty, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
||||||
t.decimal :unit_price, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
t.decimal :unit_price, :precision => 10, :scale => 2, :null => false, :default => 0.00
|
||||||
|
|||||||
Reference in New Issue
Block a user