From 907764b3e43fd0d3294e3b95072a8810060c5335 Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 8 Jun 2017 18:02:40 +0630 Subject: [PATCH] update discount --- app/assets/javascripts/orgiami.js | 30 +- .../origami/discounts_controller.rb | 36 ++ .../origami/request_bills_controller.rb | 2 +- app/models/sale_item.rb | 2 +- app/views/origami/discounts/index.html.erb | 14 +- app/views/origami/home/index.html.erb | 148 +------- app/views/origami/home/index_old.html.erb | 328 ------------------ config/routes.rb | 2 +- 8 files changed, 78 insertions(+), 484 deletions(-) delete mode 100644 app/views/origami/home/index_old.html.erb diff --git a/app/assets/javascripts/orgiami.js b/app/assets/javascripts/orgiami.js index 86db6a91..2ecdba13 100644 --- a/app/assets/javascripts/orgiami.js +++ b/app/assets/javascripts/orgiami.js @@ -97,6 +97,29 @@ $(document).ready(function(){ 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').click(function() { var sale_id=$(".selected-item").find(".orders-id").text(); @@ -105,7 +128,7 @@ $(document).ready(function(){ }); }); -/* For Receipt - discount or tax */ +/* For Receipt - Calculate discount or tax */ $(document).on('click', '.cashier_number', function(event){ if(event.handled !== true) { var original_value=0; @@ -151,6 +174,7 @@ $(document).on('click', '.cashier_number', function(event){ } }); +/* For Receipt - Update Balance */ function update_balance(){ var discount_type = $('#discount-type').val(); var discount_amount = $('#discount-amount').val(); @@ -158,8 +182,8 @@ function update_balance(){ var tax = $('#order-Tax').text(); // For Percentage Discount - if(discount_type='1'){ - discount-amount=(sub_total*discount-amount)/100; + if(discount_type == 1){ + discount_amount=(sub_total*discount_amount)/100; } var total = (parseFloat(sub_total) + parseFloat(tax)) - discount_amount; diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 717f4e09..daf68918 100644 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -8,8 +8,44 @@ class Origami::DiscountsController < BaseOrigamiController end end + #discount for selected order def create + sale_id = params[:sale_id] + discount_type = params[:discount_type] + discount_value = params[:discount_value] + discount_amount = params[:discount_amount] + grand_total = params[:grand_total] + 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 = discount_amount + sale.grand_total = grand_total + sale.save + + #save sale item for discount + sale_item = SaleItem.new + + #pull + sale_item.sale_id = sale_id + sale_item.product_code = 0 + sale_item.product_name = "Discount" + 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_root_path end end diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index c5b87b6b..2681bfcb 100644 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -26,4 +26,4 @@ class Origami::RequestBillsController < BaseOrigamiController printer.print_receipt_bill(print_settings,@sale_items,@sale_data,customer_name) redirect_to origami_root_path end - +end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 1ebd1632..5d87ff13 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -12,7 +12,7 @@ class SaleItem < ApplicationRecord def self.get_order_items_details(sale_id) - order_details = SaleItem.select("sales.total_discount as discount_amount,DATE_FORMAT(sales.receipt_date,'%Y-%m-%d %h:%m') as receipt_date, + order_details = SaleItem.select("sales.total_tax as tax_amount, sales.grand_total as grand_total_amount , sales.total_discount as discount_amount,DATE_FORMAT(sales.receipt_date,'%Y-%m-%d %h:%m') as receipt_date, sales.cashier_name,sales.receipt_no,sale_items.product_name as item_name,sale_items.qty,sale_items.price,sale_items.unit_price as total_price") .joins("left join sales on sales.sale_id = sale_items.sale_id") .where("sale_items.sale_id=?",sale_id) diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index d4d2f177..e95bdcc3 100644 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -5,7 +5,8 @@
-
ORDER DETAILS -
+ +
ORDER DETAILS
@@ -87,12 +88,12 @@
-
+
@@ -100,8 +101,11 @@
- +
+ +
+
diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index 85de2ef3..ba11124a 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -206,14 +206,15 @@
-

+
+
- + @@ -222,146 +223,3 @@
- - - diff --git a/app/views/origami/home/index_old.html.erb b/app/views/origami/home/index_old.html.erb deleted file mode 100644 index d480cf8d..00000000 --- a/app/views/origami/home/index_old.html.erb +++ /dev/null @@ -1,328 +0,0 @@ -
-
- - - - - - -
- - -
- -
- - <% if @booking_orders %> - <% @booking_orders.each do |booking_order| %> - <% if booking_order.order_status != "new" %> -
-
-

- <%=booking_order.table_name%>

- Receipt No : <%=booking_order.receipt_no%>
- Order Status : <%=booking_order.order_status %> -
-
- <% else %> -
-
-

<%=booking_order.table_name%>

- Order Status : <%=booking_order.order_status %> -
-
- <% end %> - <%end %> - <%end %> -
-
- - -
- -
- - <% if @booking_rooms %> - <% @booking_rooms.each do |booking_room| %> - <% if !booking_room.order_status = 'new'%> -
-
-

- <%=booking_room.room_name%>

- Receipt No : <%=booking_room.receipt_no%>
- Order Status : <%=booking_room.order_status %> -
-
- <% else %> -
-
-

<%=booking_room.room_name%>ddd

\ - Order Status : <%=booking_room.order_status %> -
-
- <% end %> - <%end %> - <%end %> -
-
- - -
- - -
- - <% if @orders %> - <% @orders.each do |order| %> - <% if !order.order_status = 'new'%> -
-
-

- Order No:<%=order.order_id%>

- Receipt No : <%=order.receipt_no%>
- Order Status : <%=order.order_status %> -
-
- <% else %> -
-
-

Order No:<%=order.order_id%>

- Order Status : <%=order.order_status %> -
-
- <% end %> - <%end %> - <%end %> -
-
- -
- -
- -
-
-
-
ORDER DETAILS -

-
-
-
-
- - - - - - -
ItemsQTY - Price -
-
-
- - - - - - - - - -
- - - - - -
-
- - -
-
-
- -
- - - - - - - - - - - - -
-
- - diff --git a/config/routes.rb b/config/routes.rb index ef287f3e..b1e36158 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -72,9 +72,9 @@ Rails.application.routes.draw do resources :customers, only: [:index,:new, :create ] #add customer type end - get "/request_bills/:id" => "request_bills#print" get "/discount/:id" => "discounts#index" + post "/discount" => "discounts#create" #--------- Payment ------------# get 'sale/:sale_id/payment' => 'payments#show'