control to req bill and discount ui update
This commit is contained in:
@@ -50,10 +50,13 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
|
|
||||||
# Re-calc All Amount in Sale
|
# Re-calc All Amount in Sale
|
||||||
sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f)
|
sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f)
|
||||||
|
result = {:status=> "Success", :table_id => table_id, :table_type => table_type }
|
||||||
|
else
|
||||||
|
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table_type }
|
||||||
end
|
end
|
||||||
|
|
||||||
dining = {:table_id => table_id, :table_type => table_type }
|
|
||||||
render :json => dining.to_json
|
render :json => result.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove selected discount Items
|
# Remove selected discount Items
|
||||||
@@ -78,11 +81,12 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
# sale.save
|
# sale.save
|
||||||
# Re-calc All Amount in Sale
|
# Re-calc All Amount in Sale
|
||||||
sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount)
|
sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount)
|
||||||
|
result = {:status=> "Success", :table_id => table_id, :table_type => table_type }
|
||||||
|
else
|
||||||
|
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table_type }
|
||||||
end
|
end
|
||||||
|
|
||||||
dining = {:table_id => table_id, :table_type => table_type }
|
render :json => result.to_json
|
||||||
|
|
||||||
render :json => dining.to_json
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove all discount Items
|
# Remove all discount Items
|
||||||
@@ -108,11 +112,12 @@ class Origami::DiscountsController < BaseOrigamiController
|
|||||||
|
|
||||||
# Re-calc All Amount in Sale
|
# Re-calc All Amount in Sale
|
||||||
sale.compute_by_sale_items(sale_id, sale.sale_items, 0)
|
sale.compute_by_sale_items(sale_id, sale.sale_items, 0)
|
||||||
|
result = {:status=> "Success", :table_id => table_id, :table_type => table_type }
|
||||||
|
else
|
||||||
|
result = {:status=> "Please, Check Again!", :table_id => table_id, :table_type => table_type }
|
||||||
end
|
end
|
||||||
|
|
||||||
dining = {:table_id => table_id, :table_type => table_type }
|
render :json => result.to_json
|
||||||
|
|
||||||
render :json => dining.to_json
|
|
||||||
end
|
end
|
||||||
|
|
||||||
#discount for selected order
|
#discount for selected order
|
||||||
|
|||||||
@@ -5,19 +5,24 @@ class Origami::RequestBillsController < BaseOrigamiController
|
|||||||
@sale = Sale.new
|
@sale = Sale.new
|
||||||
sale_order=SaleOrder.new
|
sale_order=SaleOrder.new
|
||||||
|
|
||||||
order_id = params[:id] # order_id
|
if ShiftSale.current_open_shift(current_user.id)
|
||||||
bk_order = BookingOrder.find_by_order_id(order_id)
|
order_id = params[:id] # order_id
|
||||||
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
|
bk_order = BookingOrder.find_by_order_id(order_id)
|
||||||
if check_booking.sale_id.nil?
|
check_booking = Booking.find_by_booking_id(bk_order.booking_id)
|
||||||
# Create Sale if it doesn't exist
|
if check_booking.sale_id.nil?
|
||||||
# puts "current_login_employee"
|
# Create Sale if it doesn't exist
|
||||||
# puts current_login_employee.name
|
# puts "current_login_employee"
|
||||||
@status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, cashier = nil)
|
# puts current_login_employee.name
|
||||||
@sale_data = Sale.find_by_sale_id(@sale_id)
|
@status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, cashier = nil)
|
||||||
@sale_items = SaleItem.where("sale_id=?",@sale_id)
|
@sale_data = Sale.find_by_sale_id(@sale_id)
|
||||||
|
@sale_items = SaleItem.where("sale_id=?",@sale_id)
|
||||||
|
else
|
||||||
|
@sale_data = Sale.find_by_sale_id(check_booking.sale_id)
|
||||||
|
@sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
@sale_data = Sale.find_by_sale_id(check_booking.sale_id)
|
@status = false
|
||||||
@sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id)
|
@error_message = "No Current Open Shift for This Employee"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Not Use for these printed bill cannot give customer
|
# Not Use for these printed bill cannot give customer
|
||||||
|
|||||||
@@ -352,13 +352,24 @@ $(document).ready(function(){
|
|||||||
url: ajax_url,
|
url: ajax_url,
|
||||||
data: params,
|
data: params,
|
||||||
success:function(result){
|
success:function(result){
|
||||||
alert("Successfully Discount!");
|
$.confirm({
|
||||||
if(result.table_type == "Table"){
|
title: 'Infomation!',
|
||||||
window.location.href = "/origami/table/" + result.table_id
|
content: result.status,
|
||||||
}
|
buttons: {
|
||||||
else {
|
confirm: {
|
||||||
window.location.href = "/origami/room/" + result.table_id
|
text: 'Ok',
|
||||||
}
|
btnClass: 'btn-green',
|
||||||
|
action: function(){
|
||||||
|
if(result.table_type == "Table"){
|
||||||
|
window.location.href = "/origami/table/" + result.table_id
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.location.href = "/origami/room/" + result.table_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -372,8 +383,19 @@ $(document).ready(function(){
|
|||||||
// Selected Items
|
// Selected Items
|
||||||
var sale_items = get_selected_sale_items();
|
var sale_items = get_selected_sale_items();
|
||||||
if(sale_items.length == 0){
|
if(sale_items.length == 0){
|
||||||
alert("You have no selected item!");
|
$.confirm({
|
||||||
return;
|
title: 'Infomation!',
|
||||||
|
content: "You have no selected item!",
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
text: 'Ok',
|
||||||
|
btnClass: 'btn-green',
|
||||||
|
action: function(){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
for(var i=0;i < sale_items.length;i++){
|
for(var i=0;i < sale_items.length;i++){
|
||||||
@@ -381,8 +403,19 @@ $(document).ready(function(){
|
|||||||
discount_items.push(sale_items[i]);
|
discount_items.push(sale_items[i]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
alert("You have selected no discount item!");
|
$.confirm({
|
||||||
return;
|
title: 'Infomation!',
|
||||||
|
content: "You have selected no discount item!!",
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
text: 'Ok',
|
||||||
|
btnClass: 'btn-green',
|
||||||
|
action: function(){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -392,13 +425,24 @@ $(document).ready(function(){
|
|||||||
url: "/origami/" + sale_id + "/remove_discount_items",
|
url: "/origami/" + sale_id + "/remove_discount_items",
|
||||||
data: params,
|
data: params,
|
||||||
success: function(result){
|
success: function(result){
|
||||||
alert('Removed Discount');
|
$.confirm({
|
||||||
if(result.table_type == "Table"){
|
title: 'Infomation!',
|
||||||
window.location.href = "/origami/table/" + result.table_id
|
content: result.status,
|
||||||
}
|
buttons: {
|
||||||
else {
|
confirm: {
|
||||||
window.location.href = "/origami/room/" + result.table_id
|
text: 'Ok',
|
||||||
}
|
btnClass: 'btn-green',
|
||||||
|
action: function(){
|
||||||
|
if(result.table_type == "Table"){
|
||||||
|
window.location.href = "/origami/table/" + result.table_id
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.location.href = "/origami/room/" + result.table_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -410,13 +454,24 @@ $(document).ready(function(){
|
|||||||
type: "GET",
|
type: "GET",
|
||||||
url: "/origami/" + sale_id + "/remove_all_discount",
|
url: "/origami/" + sale_id + "/remove_all_discount",
|
||||||
success: function(result){
|
success: function(result){
|
||||||
alert('Removed All Discount');
|
$.confirm({
|
||||||
if(result.table_type == "Table"){
|
title: 'Infomation!',
|
||||||
window.location.href = "/origami/table/" + result.table_id
|
content: result.status,
|
||||||
}
|
buttons: {
|
||||||
else {
|
confirm: {
|
||||||
window.location.href = "/origami/room/" + result.table_id
|
text: 'Ok',
|
||||||
}
|
btnClass: 'btn-green',
|
||||||
|
action: function(){
|
||||||
|
if(result.table_type == "Table"){
|
||||||
|
window.location.href = "/origami/table/" + result.table_id
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
window.location.href = "/origami/room/" + result.table_id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -540,10 +595,23 @@ function calculate_overall_discount(type, amount){
|
|||||||
// For Percentage Pay
|
// For Percentage Pay
|
||||||
if(type == 1){
|
if(type == 1){
|
||||||
if(amount > 100 ){
|
if(amount > 100 ){
|
||||||
aler("Percentage Value over 100!");
|
$.confirm({
|
||||||
return;
|
title: 'Infomation!',
|
||||||
|
content: "Percentage Value over 100!",
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
text: 'Ok',
|
||||||
|
btnClass: 'btn-green',
|
||||||
|
action: function(){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
total_discount = (origin_sub_total * amount)/100;
|
||||||
}
|
}
|
||||||
total_discount = (origin_sub_total * amount)/100;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#order-discount").text(total_discount);
|
$("#order-discount").text(total_discount);
|
||||||
@@ -562,7 +630,7 @@ function calculate_item_discount(type, amount, sale_items, account_types){
|
|||||||
for(var i=0;i < sale_items.length;i++){
|
for(var i=0;i < sale_items.length;i++){
|
||||||
if(account_types.length > 0){
|
if(account_types.length > 0){
|
||||||
for(var j=0; j < account_types.length; j++){
|
for(var j=0; j < account_types.length; j++){
|
||||||
if(sale_items[i].account_id != account_types[j].id){
|
if(sale_items[i].account_id == account_types[j].id){
|
||||||
// Discount Items
|
// Discount Items
|
||||||
var discount_item_row = item_row_template(type, sale_items[i], dis_amount, amount);
|
var discount_item_row = item_row_template(type, sale_items[i], dis_amount, amount);
|
||||||
$("#order-items-table tbody").append(discount_item_row);
|
$("#order-items-table tbody").append(discount_item_row);
|
||||||
@@ -604,34 +672,45 @@ function calculate_item_discount(type, amount, sale_items, account_types){
|
|||||||
// For Percentage Pay
|
// For Percentage Pay
|
||||||
if(type == 1){
|
if(type == 1){
|
||||||
if(amount > 100 ){
|
if(amount > 100 ){
|
||||||
aler("Percentage Value over 100!");
|
$.confirm({
|
||||||
return;
|
title: 'Infomation!',
|
||||||
|
content: "Percentage Value over 100!",
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
text: 'Ok',
|
||||||
|
btnClass: 'btn-green',
|
||||||
|
action: function(){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
// Check sale items exists
|
// Check sale items exists
|
||||||
if(sale_items.length > 0){
|
if(sale_items.length > 0){
|
||||||
for(var i=0;i < sale_items.length;i++){
|
for(var i=0;i < sale_items.length;i++){
|
||||||
if(account_types.length > 0){
|
if(account_types.length > 0){
|
||||||
for(var j=0; j < account_types.length; j++){
|
for(var j=0; j < account_types.length; j++){
|
||||||
if(sale_items[i].account_id != account_types[j].id){
|
if(sale_items[i].account_id == account_types[j].id){
|
||||||
// Discount Items
|
// Discount Items
|
||||||
dis_amount = 0 - ((sale_items[i].price * amount)/100);
|
dis_amount = 0 - ((sale_items[i].price * amount)/100);
|
||||||
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
|
var discount_item_row = item_row_template(type,sale_items[i], dis_amount, amount);
|
||||||
$("#order-items-table tbody").append(discount_item_row);
|
$("#order-items-table tbody").append(discount_item_row);
|
||||||
total_discount = total_discount + dis_amount;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
sub_total = origin_sub_total + total_discount;
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// No Needs For Auto Selected
|
// No Needs For Auto Selected
|
||||||
// Check account types exists
|
// Check account types exists
|
||||||
// if(account_types.length > 0){
|
// if(account_types.length > 0){
|
||||||
@@ -654,8 +733,6 @@ function calculate_item_discount(type, amount, sale_items, account_types){
|
|||||||
// alert("No Items!");
|
// alert("No Items!");
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
sub_total = origin_sub_total + total_discount;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#order-sub-total").text(sub_total);
|
$("#order-sub-total").text(sub_total);
|
||||||
|
|||||||
@@ -469,8 +469,24 @@ $('#request_bills').click(function() {
|
|||||||
url: ajax_url,
|
url: ajax_url,
|
||||||
// data: 'order_id='+ order_id,
|
// data: 'order_id='+ order_id,
|
||||||
success:function(result){
|
success:function(result){
|
||||||
|
if(!result.status){
|
||||||
location.reload();
|
$.confirm({
|
||||||
|
title: 'Infomation!',
|
||||||
|
content: result.error_message,
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
text: 'Ok',
|
||||||
|
btnClass: 'btn-green',
|
||||||
|
action: function(){
|
||||||
|
window.location.href = '/origami';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1 +1,7 @@
|
|||||||
json.status true
|
if @status == true
|
||||||
|
#show invoice number and stuff
|
||||||
|
json.status @status
|
||||||
|
else
|
||||||
|
json.status @status
|
||||||
|
json.error_message @error_message
|
||||||
|
end
|
||||||
|
|||||||
@@ -457,8 +457,24 @@ $('#request_bills').click(function() {
|
|||||||
url: ajax_url,
|
url: ajax_url,
|
||||||
// data: 'order_id='+ order_id,
|
// data: 'order_id='+ order_id,
|
||||||
success:function(result){
|
success:function(result){
|
||||||
|
if(!result.status){
|
||||||
location.reload();
|
$.confirm({
|
||||||
|
title: 'Infomation!',
|
||||||
|
content: result.error_message,
|
||||||
|
buttons: {
|
||||||
|
confirm: {
|
||||||
|
text: 'Ok',
|
||||||
|
btnClass: 'btn-green',
|
||||||
|
action: function(){
|
||||||
|
window.location.href = '/origami';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user