control to req bill and discount ui update

This commit is contained in:
Yan
2017-07-08 23:29:31 +06:30
parent 1666cb3d0c
commit c73cfa4c2d
6 changed files with 207 additions and 82 deletions

View File

@@ -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

View File

@@ -5,6 +5,7 @@ class Origami::RequestBillsController < BaseOrigamiController
@sale = Sale.new @sale = Sale.new
sale_order=SaleOrder.new sale_order=SaleOrder.new
if ShiftSale.current_open_shift(current_user.id)
order_id = params[:id] # order_id order_id = params[:id] # order_id
bk_order = BookingOrder.find_by_order_id(order_id) bk_order = BookingOrder.find_by_order_id(order_id)
check_booking = Booking.find_by_booking_id(bk_order.booking_id) check_booking = Booking.find_by_booking_id(bk_order.booking_id)
@@ -19,6 +20,10 @@ class Origami::RequestBillsController < BaseOrigamiController
@sale_data = Sale.find_by_sale_id(check_booking.sale_id) @sale_data = Sale.find_by_sale_id(check_booking.sale_id)
@sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id) @sale_items = SaleItem.where("sale_id=?",@sale_data.sale_id)
end end
else
@status = false
@error_message = "No Current Open Shift for This Employee"
end
# Not Use for these printed bill cannot give customer # Not Use for these printed bill cannot give customer
# unique_code = "ReceiptBillPdf" # unique_code = "ReceiptBillPdf"

View File

@@ -352,7 +352,14 @@ $(document).ready(function(){
url: ajax_url, url: ajax_url,
data: params, data: params,
success:function(result){ success:function(result){
alert("Successfully Discount!"); $.confirm({
title: 'Infomation!',
content: result.status,
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-green',
action: function(){
if(result.table_type == "Table"){ if(result.table_type == "Table"){
window.location.href = "/origami/table/" + result.table_id window.location.href = "/origami/table/" + result.table_id
} }
@@ -360,6 +367,10 @@ $(document).ready(function(){
window.location.href = "/origami/room/" + result.table_id window.location.href = "/origami/room/" + result.table_id
} }
} }
}
}
});
}
}); });
}); });
@@ -372,19 +383,41 @@ $(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({
title: 'Infomation!',
content: "You have no selected item!",
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-green',
action: function(){
return; return;
} }
}
}
});
}
for(var i=0;i < sale_items.length;i++){ for(var i=0;i < sale_items.length;i++){
if(sale_items[i].price < 0){ if(sale_items[i].price < 0){
discount_items.push(sale_items[i]); discount_items.push(sale_items[i]);
} }
else { else {
alert("You have selected no discount item!"); $.confirm({
title: 'Infomation!',
content: "You have selected no discount item!!",
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-green',
action: function(){
return; return;
} }
} }
}
});
}
}
var params = { 'sale_id': sale_id, 'discount_items': JSON.stringify(discount_items) }; var params = { 'sale_id': sale_id, 'discount_items': JSON.stringify(discount_items) };
$.ajax({ $.ajax({
@@ -392,7 +425,14 @@ $(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({
title: 'Infomation!',
content: result.status,
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-green',
action: function(){
if(result.table_type == "Table"){ if(result.table_type == "Table"){
window.location.href = "/origami/table/" + result.table_id window.location.href = "/origami/table/" + result.table_id
} }
@@ -400,6 +440,10 @@ $(document).ready(function(){
window.location.href = "/origami/room/" + result.table_id window.location.href = "/origami/room/" + result.table_id
} }
} }
}
}
});
}
}); });
}); });
@@ -410,7 +454,14 @@ $(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({
title: 'Infomation!',
content: result.status,
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-green',
action: function(){
if(result.table_type == "Table"){ if(result.table_type == "Table"){
window.location.href = "/origami/table/" + result.table_id window.location.href = "/origami/table/" + result.table_id
} }
@@ -418,6 +469,10 @@ $(document).ready(function(){
window.location.href = "/origami/room/" + result.table_id window.location.href = "/origami/room/" + result.table_id
} }
} }
}
}
});
}
}); });
}); });
@@ -540,11 +595,24 @@ 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({
title: 'Infomation!',
content: "Percentage Value over 100!",
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-green',
action: function(){
return; 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,16 +672,27 @@ 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({
title: 'Infomation!',
content: "Percentage Value over 100!",
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-green',
action: function(){
return; 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);
@@ -627,11 +706,11 @@ function calculate_item_discount(type, amount, sale_items, account_types){
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;
} }
} }
sub_total = origin_sub_total + total_discount;
}
} }
// 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);

View File

@@ -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){
$.confirm({
title: 'Infomation!',
content: result.error_message,
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-green',
action: function(){
window.location.href = '/origami';
}
}
}
});
}
else {
location.reload(); location.reload();
}
} }
}); });
}); });

View File

@@ -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

View File

@@ -457,9 +457,25 @@ $('#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){
$.confirm({
title: 'Infomation!',
content: result.error_message,
buttons: {
confirm: {
text: 'Ok',
btnClass: 'btn-green',
action: function(){
window.location.href = '/origami';
}
}
}
});
}
else {
location.reload(); location.reload();
} }
}
}); });
}); });