From 4501762300174a235898fe86e0e6180c71177204 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Thu, 10 Aug 2017 14:50:47 +0630 Subject: [PATCH 01/20] start for oqs --- app/controllers/oqs/backhome_controller.rb | 126 +++++++++++++ app/controllers/oqs/home_controller.rb | 39 ++-- app/views/oqs/home/bkindex.html.erb | 197 +++++++++++++++++++++ app/views/oqs/home/index.html.erb | 20 +-- 4 files changed, 351 insertions(+), 31 deletions(-) create mode 100644 app/controllers/oqs/backhome_controller.rb create mode 100644 app/views/oqs/home/bkindex.html.erb diff --git a/app/controllers/oqs/backhome_controller.rb b/app/controllers/oqs/backhome_controller.rb new file mode 100644 index 00000000..cef7c6b6 --- /dev/null +++ b/app/controllers/oqs/backhome_controller.rb @@ -0,0 +1,126 @@ +class Oqs::HomeController < BaseOqsController + def index + queue_stations=OrderQueueStation.all + + # Query for OQS with delivery status false + @queue_items_details = queue_items_query(false) + + # Query for OQS with delivery status true + @queue_completed_item = completed_order + + @queue_stations_items=Array.new + + # Calculate Count for each station tab + queue_stations.each do |que| + i = 0 + zone_id = 0 + @queue_items_details.each do |qid| + dining = DiningFacility.find_by_name(qid.zone) + que.order_queue_process_by_zones.each do |qz| + if qid.station_id == qz.order_queue_station_id && qid.zone_id == qz.zone_id + zone_id = qid.zone_id + i=i+1 + end + end + end + @queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i }) + end + + # @queue_items_details = @queue_items_details.paginate(:per_page => 10, :page => params[:page]) + @queue_stations_items + end + + # Get Order items + def get_order_items + items = [] + table_name = params[:table_id] + status = params[:status] + dining = DiningFacility.find_by_name(table_name); + # oqpz = OrderQueueProcessByZone.find_by_zone_id(dining.zone_id) + # if status == "" + # AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=0").find_each do |aoi| + # oi = OrderItem.find_by_item_code(aoi.item_code) + # items.push(oi) + # end + # else + # AssignedOrderItem.where("order_queue_station_id=#{ oqpz.order_queue_station_id } AND delivery_status=1").find_each do |aoi| + # oi = OrderItem.find_by_item_code(aoi.item_code) + # items.push(oi) + # end + # end + + booking = Booking.find_by_dining_facility_id(dining.id) + BookingOrder.where("booking_id='#{ booking.booking_id }'").find_each do |bo| + order=Order.find(bo.order_id) + order.order_items.each do |oi| + items.push(oi) + end + end + + # booking_id = dining.get_new_booking + # BookingOrder.where("booking_id='#{ booking_id }'").find_each do |bo| + # order=Order.find(bo.order_id); + # order.order_items.each do |oi| + # items.push(oi) + # end + # end + + render :json => items.to_json + end + + def show + end + + # update delivery status when complete click + def update_delivery_status + removed_item = [] + assigned_item_id = params[:id] + assigned_item=AssignedOrderItem.find(assigned_item_id) + assigned_items=AssignedOrderItem.where("item_code='" + assigned_item.item_code + "' AND " + "order_id='" + assigned_item.order_id + "'"); + + # update delivery status for completed same order items + assigned_items.each do |ai| + ai.delivery_status=true + ai.save + removed_item.push(ai.assigned_order_item_id) + end + render :json => removed_item.to_json + end + + # Query for OQS with delivery status + def queue_items_query(status) + AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") + .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id + left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id + left join orders as od ON od.order_id = assigned_order_items.order_id + left join order_items as odt ON odt.item_code = assigned_order_items.item_code AND odt.order_id = assigned_order_items.order_id + left join customers as cus ON cus.customer_id = od.customer_id + left join booking_orders as bo on bo.order_id = assigned_order_items.order_id + left join bookings as bk on bk.booking_id = bo.booking_id + left join dining_facilities as df on df.id = bk.dining_facility_id") + .where("assigned_order_items.delivery_status = #{status} AND odt.price <> 0 AND assigned_order_items.created_at >= '#{Time.now.beginning_of_day.utc}'") + .group("assigned_order_items.assigned_order_item_id") + .order("assigned_order_items.created_at") + end + + # Completed Order + def completed_order + AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") + .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id + left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id + left join orders as od ON od.order_id = assigned_order_items.order_id + left join order_items as odt ON odt.item_code = assigned_order_items.item_code AND odt.order_id = assigned_order_items.order_id + left join customers as cus ON cus.customer_id = od.customer_id + left join booking_orders as bo on bo.order_id = assigned_order_items.order_id + left join bookings as bk on bk.booking_id = bo.booking_id + left join dining_facilities as df on df.id = bk.dining_facility_id") + .where("assigned_order_items.delivery_status = true AND odt.price <> 0 AND assigned_order_items.created_at between '#{Time.now.beginning_of_day.utc}' and '#{Time.now.end_of_day.utc}'") + .group("assigned_order_items.order_id") + .limit(20) + .order("assigned_order_items.created_at") + + + # completed_order = AssignedOrderItem.group(:order_id).where('delivery_status=true'); + end + +end diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index cef7c6b6..c4c801fa 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -1,33 +1,34 @@ class Oqs::HomeController < BaseOqsController def index - queue_stations=OrderQueueStation.all + + @queue_stations = OrderQueueStation.all # Query for OQS with delivery status false - @queue_items_details = queue_items_query(false) + # @queue_items_details = queue_items_query(false) # Query for OQS with delivery status true @queue_completed_item = completed_order - @queue_stations_items=Array.new + # @queue_stations_items=Array.new # Calculate Count for each station tab - queue_stations.each do |que| - i = 0 - zone_id = 0 - @queue_items_details.each do |qid| - dining = DiningFacility.find_by_name(qid.zone) - que.order_queue_process_by_zones.each do |qz| - if qid.station_id == qz.order_queue_station_id && qid.zone_id == qz.zone_id - zone_id = qid.zone_id - i=i+1 - end - end - end - @queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i }) - end + # @queue_stations.each do |que| + # i = 0 + # zone_id = 0 + # @queue_items_details.each do |qid| + # dining = DiningFacility.find_by_name(qid.zone) + # que.order_queue_process_by_zones.each do |qz| + # if qid.station_id == qz.order_queue_station_id && qid.zone_id == qz.zone_id + # zone_id = qid.zone_id + # i=i+1 + # end + # end + # end + # @queue_stations_items.push({:zone_id => zone_id , :station_name => que.station_name, :is_active => que.is_active , :is_ap => que.auto_print, :item_count => i }) + # end - # @queue_items_details = @queue_items_details.paginate(:per_page => 10, :page => params[:page]) - @queue_stations_items + # # @queue_items_details = @queue_items_details.paginate(:per_page => 10, :page => params[:page]) + # @queue_stations_items end # Get Order items diff --git a/app/views/oqs/home/bkindex.html.erb b/app/views/oqs/home/bkindex.html.erb new file mode 100644 index 00000000..be62d989 --- /dev/null +++ b/app/views/oqs/home/bkindex.html.erb @@ -0,0 +1,197 @@ +
+ +
+ + + + +
+ +
+
+ <% + @queue_completed_item.each do |qid| + %> +
+
+

+ <%= qid.type %> - + <%= qid.zone %> + <%= qid.order_id %> +

+

+ + <%= qid.item_name %> + [x + + <%= qid.qty %> + ] +

+ +

<%= qid.options == "[]"? "" : qid.options %>

+ +

+ Order at + + <%= qid.created_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") %> + - + + <%= qid.item_order_by %> + + +

+ + + +
+
+ <% + end + %> +
+
+ + + + <% + @queue_stations_items.each do |qsi| + %> + +
role="tabpanel"> + +
+ <% + @queue_items_details.each do |qid| + if qid.price != 0 + if qid.zone_id == qsi[:zone_id] && qid.station_name == qsi[:station_name] + %> +
+
+

+ <%= qid.type %> - + <%= qid.zone %> + <%= qid.order_id %> +

+

+ <%= qid.item_name %> [x + <%= qid.qty %> ] +

+ +

<%= qid.options == "[]"? "" : qid.options %>

+ +

+ Order at + + <%= qid.created_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") %> + - + + <%= qid.item_order_by %> + + +

+ + + +
+ +
+ <% + end + end + end + %> + + +
+
+ + <% end %> + +
+
+ + +
+
+
+
ORDER DETAILS - Table
+
+
+
+ + + + + + + + + + + + + + + + + +
Order ByOrder At + Customer +
Table/Room
+
+
+ + + + + + + + + + +
ItemsQTY
+
+ +
+
+
+ + +
+ + + Back + + +
+
+ diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 71077ec4..ed27aa13 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -1,29 +1,25 @@
-
@@ -193,4 +144,82 @@
+ diff --git a/config/routes.rb b/config/routes.rb index 0753b64b..599ec8c8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -198,6 +198,8 @@ Rails.application.routes.draw do # Pass assigned_order_item_id get 'print/print/:id', to: "print#print" get 'print/print_order_summary/:id', to: "print#print_order_summary" + + get "/get_items/:id" =>"home#get_items_by_oqs", :as => "get_order_items_by_oqs" #dashboard # end From a368c4b0b690063452a16604a7bdbc78cab04a05 Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 10 Aug 2017 18:25:10 +0630 Subject: [PATCH 04/20] date convert oqs --- app/views/oqs/home/index.html.erb | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 857d9cb7..02e5837f 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -77,13 +77,11 @@ - -
- - - -
- + +
+ +
+ @@ -175,7 +173,7 @@ function show_details(url){ options = data.options; } - var date = data[field]["created_at"]; + var date = new Date(data[field]["created_at"] + " UTC"); row ='
' +'
' @@ -194,7 +192,7 @@ function show_details(url){ +'

' +'Order at' - +''+ date +' - ' + +''+ date.toLocalString() +' - ' +''+ data[field]["item_order_by"] +' ' +' ' From d32fbf18e097d57875f586df57d7f95d175fd4ef Mon Sep 17 00:00:00 2001 From: Yan Date: Thu, 10 Aug 2017 18:45:59 +0630 Subject: [PATCH 05/20] update oqs --- app/views/oqs/home/index.html.erb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 02e5837f..ad683d40 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -173,7 +173,8 @@ function show_details(url){ options = data.options; } - var date = new Date(data[field]["created_at"] + " UTC"); + var date = new Date(data[field]["created_at"]); + var show_date = date.getDate() + "-" + date.getMonth() + "-" + date.getFullYear() + ' ' + date.getHours()+ ':' + date.getMinutes(); row ='

' +'
' @@ -192,7 +193,7 @@ function show_details(url){ +'

' +'Order at' - +''+ date.toLocalString() +' - ' + +''+ show_date +' - ' +''+ data[field]["item_order_by"] +' ' +' ' From 9eaf04778c0a305f2ba194c52fd1b0b7f3ce1ce4 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 11 Aug 2017 10:25:09 +0630 Subject: [PATCH 06/20] update oqs --- app/assets/javascripts/OQS.js | 86 +++++++++++++++++++++++++++++-- app/views/oqs/home/index.html.erb | 78 ---------------------------- 2 files changed, 82 insertions(+), 82 deletions(-) diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index d77a3a6a..54e73fe1 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -24,6 +24,81 @@ $(document).ready(function(){ // window.location.reload(1); // }, 10000); + $(".oqs_click").on("click", function(){ + + var oqs_id = $(this).find(".oqs-id").text(); + var url = 'oqs/get_items/'+oqs_id; + show_details(url); + + }); //End Click + + function show_details(url){ + var oqs_append = $('.oqs_append'); + oqs_append.empty(); + + //Start Ajax + $.ajax({ + type: "GET", + url: url, + data: {}, + dataType: "json", + success: function(data) { + for(var field in data) { + var price = parseFloat(data[field].price).toFixed(2); + + if (data[field]["options"] == "[]") { + var options = ""; + }else{ + var options = data.options; + } + + var date = data[field]["created_at"]; + + row ='

' + +'
' + +'

' + +''+data[field]["zone"]+'- ' + +''+ data[field]["zone"] +'' + +''+ data[field]["order_id"] +'- ' + +'

' + + +'

' + +''+ data[field]["item_name"] +'- ' + +''+ data[field]["qty"] +'- ' + +'

' + + +'

'+ options +'

' + + +'

' + +'Order at' + +''+ date +' - ' + + +''+ data[field]["item_order_by"] +' ' + +' ' + +'

' + + +' ' + +' ' + +'
' + + +'' + + +'
'; + + + + $('.oqs_append').append(row); + } + + } + }); + //end Ajax + + } + $(document).on('click', '.queue_station', function(event){ var orderZone=$(this).children().children().children('.order-zone').text().trim(); // var orderItem=$(this).children().children().children('.order-item').text(); @@ -41,7 +116,6 @@ $(document).ready(function(){ $('#order-from').text(orderZone); // clear order items $("#oqs-order-details-table").children("tbody").empty(); - // Call get_order_items() for Order Items by dining $.ajax({ type: 'GET', @@ -76,7 +150,7 @@ $(document).ready(function(){ // complete for queue item - $(document).on('click', '.order-complete', function(event){ + $(document).on('click', '.order-complete', function(event){ //e.preventDefault(); var _self = $(this); // To know in ajax return var assigned_item_id=$(this).attr('id').substr(15); @@ -118,10 +192,13 @@ $(document).ready(function(){ }); // Print Order Item - $('#print_order_item').on('click',function(){ + $(document).on('click', '#print_order_item', function(event){ var assigned_item_id = $('.selected-item').children('.card-block').children('.assigned-order-item').text(); var options = $('.selected-item').children('.card-block').find('.item-options').text(); var params = { 'options':options }; + console.log(assigned_item_id); + console.log(options); + console.log(params); $.ajax({ type: 'GET', url: '/oqs/print/print/'+assigned_item_id, @@ -130,7 +207,8 @@ $(document).ready(function(){ }); // Print Order Summary - $('#print_order_summary').on('click',function(){ + // $('#print_order_summary').on('click',function(){ + $(document).on('click', '#print_order_summary', function(event){ var table_name=$('.selected-item').children().children().children('.order-zone').text().trim(); var assigned_item_id=$('.selected-item').children('.card-block').children('.assigned-order-item').text(); var params = { 'table_name':table_name }; diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 857d9cb7..5642e4f7 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -144,82 +144,4 @@
- From 0e93eb37651c9d5741db1274a968ec98605c7df5 Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 11 Aug 2017 12:13:30 +0630 Subject: [PATCH 07/20] fix for customer tax ui and calc tax after bind customer --- app/controllers/origami/customers_controller.rb | 2 ++ app/models/sale.rb | 14 ++++++++++---- app/views/crm/customers/index.html.erb | 6 ++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index ec826416..9c054378 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -89,6 +89,8 @@ class Origami::CustomersController < BaseOrigamiController if status == true render json: JSON.generate({:status => true}) + # Re-calc All Amount in Sale + sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount) else render json: JSON.generate({:status => false, :error_message => "Record not found"}) end diff --git a/app/models/sale.rb b/app/models/sale.rb index 9f4ae9f7..7a4a7a62 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -274,11 +274,14 @@ class Sale < ApplicationRecord #tax_profile - list by order_by tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(sale.customer_id) - +puts customer.tax_profiles # #Creat new tax records tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax.to_i == tax.id + customer.tax_profiles.each do |cus_tax| +puts tax +puts cus_tax + if cus_tax.to_i == tax.id +puts "WALSS" sale_tax = SaleTax.new(:sale => sale) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -319,11 +322,14 @@ class Sale < ApplicationRecord tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(self.customer_id) - +puts customer.tax_profiles # #Create new tax records tax_profiles.each do |tax| customer.tax_profiles.each do |cus_tax| +puts tax +puts cus_tax if cus_tax.to_i == tax.id +puts "WALSS" sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 34aaf51e..14e38822 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -124,18 +124,20 @@ $(document).on('click',".customer_tr",function(){ var url = "customers/" + customer_id + "/edit"; } + $("#customer_tax_profiles").children().removeAttr("selected").css({'color':'#000','background':'none'});; + $.ajax({ type: "GET", url: url, data: {}, dataType: "json", - success: function(data) { + success: function(data) { // Selected for Taxes var taxes = JSON.stringify(data.tax_profiles); var parse_taxes = JSON.parse(taxes); console.log(parse_taxes); $.each(parse_taxes, function(i, value){ - $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected"); + $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected").css({'color':'#fff','background':'#215d9c'}); }); $('#customer_id').val(data.id); From ed793bd48cd0a8b698843fd916ffecf6fb626cca Mon Sep 17 00:00:00 2001 From: Yan Date: Fri, 11 Aug 2017 12:15:47 +0630 Subject: [PATCH 08/20] remove puts in sale --- app/models/sale.rb | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/app/models/sale.rb b/app/models/sale.rb index 7a4a7a62..a73667ba 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -274,14 +274,10 @@ class Sale < ApplicationRecord #tax_profile - list by order_by tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(sale.customer_id) -puts customer.tax_profiles # #Creat new tax records tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| -puts tax -puts cus_tax - if cus_tax.to_i == tax.id -puts "WALSS" + customer.tax_profiles.each do |cus_tax| + if cus_tax.to_i == tax.id sale_tax = SaleTax.new(:sale => sale) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -322,14 +318,10 @@ puts "WALSS" tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(self.customer_id) -puts customer.tax_profiles # #Create new tax records tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| -puts tax -puts cus_tax - if cus_tax.to_i == tax.id -puts "WALSS" + customer.tax_profiles.each do |cus_tax| + if cus_tax.to_i == tax.id sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate From 2c7a641d47422d0426dfea8a3f179dbfc4ddce4b Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 11 Aug 2017 13:21:40 +0630 Subject: [PATCH 09/20] update oqs --- app/assets/javascripts/OQS.js | 8 +++++--- app/controllers/oqs/backhome_controller.rb | 2 +- app/controllers/oqs/home_controller.rb | 10 +++++++--- app/views/oqs/home/index.html.erb | 3 +-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index cad815bf..19d0429e 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -46,7 +46,8 @@ $(document).ready(function(){ url: url, data: {}, dataType: "json", - success: function(data) { + success: function(data) { + for(var field in data) { var price = parseFloat(data[field].price).toFixed(2); @@ -62,7 +63,7 @@ $(document).ready(function(){ row ='
' +'
' +'

' - +''+data[field]["type"]+'- ' + +''+data[field]["table_type"]+'- ' +''+ data[field]["zone"] +'' +''+ data[field]["order_id"] +'- ' +'

' @@ -200,7 +201,8 @@ $(document).ready(function(){ $(document).on('click', '#print_order_item', function(event){ var assigned_item_id = $('.selected-item').children('.card-block').children('.assigned-order-item').text(); var options = $('.selected-item').children('.card-block').find('.item-options').text(); - var params = { 'options':options }; + var params = { 'options':options }; + $.ajax({ type: 'GET', url: '/oqs/print/print/'+assigned_item_id, diff --git a/app/controllers/oqs/backhome_controller.rb b/app/controllers/oqs/backhome_controller.rb index b09e4a2d..4ac5f0a2 100644 --- a/app/controllers/oqs/backhome_controller.rb +++ b/app/controllers/oqs/backhome_controller.rb @@ -89,7 +89,7 @@ class Oqs::HomeController < BaseOqsController # Query for OQS with delivery status def queue_items_query(status) - AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") + AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type as type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id left join orders as od ON od.order_id = assigned_order_items.order_id diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index d25ab0ac..dfe648d0 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -95,7 +95,6 @@ class Oqs::HomeController < BaseOqsController end - # Query for OQS with delivery status def queue_items_query(status,oqs_id=nil) if oqs_id == nil @@ -103,7 +102,13 @@ class Oqs::HomeController < BaseOqsController else oqs = "and assigned_order_items.order_queue_station_id = '#{oqs_id}' " end - AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type as type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") + AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, + oqs.id as station_id, oqs.station_name, + oqs.is_active, oqpz.zone_id, + df.name as zone, df.type as table_type, + odt.order_id, odt.item_code, odt.item_name, + odt.price, odt.qty, odt.item_order_by, odt.options, + cus.name as customer_name, odt.created_at") .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id left join orders as od ON od.order_id = assigned_order_items.order_id @@ -114,7 +119,6 @@ class Oqs::HomeController < BaseOqsController left join dining_facilities as df on df.id = bk.dining_facility_id") .where("assigned_order_items.delivery_status = #{status} AND odt.price <> 0 AND assigned_order_items.created_at >= '#{Time.now.beginning_of_day.utc}' #{oqs}") .group("assigned_order_items.assigned_order_item_id") - .order("assigned_order_items.created_at") end diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index c6c35e1c..3ab1cf24 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -17,12 +17,11 @@ > <%= qsi.station_name %> - <%= qsi.assigned_order_items.count(:delivery_status) %> + <%= qsi.assigned_order_items.where("delivery_status=0").count %> <% if qsi.auto_print %> (ap) <% end %> - <%= qsi.assigned_order_items.where("delivery_status=0").count %> <% end %> From b0ad2049c591a89a3a14567a5500654dbc2fb177 Mon Sep 17 00:00:00 2001 From: Nweni Date: Fri, 11 Aug 2017 13:34:30 +0630 Subject: [PATCH 10/20] dining_charges --- app/assets/javascripts/dining_charges.coffee | 3 + app/assets/stylesheets/dining_charges.scss | 3 + app/controllers/dining_charges_controller.rb | 74 +++++++++ app/helpers/dining_charges_helper.rb | 2 + app/models/dining_charge.rb | 2 + .../_dining_charge.json.jbuilder | 2 + app/views/dining_charges/_form.html.erb | 10 ++ app/views/dining_charges/edit.html.erb | 6 + app/views/dining_charges/index.html.erb | 25 ++++ app/views/dining_charges/index.json.jbuilder | 1 + app/views/dining_charges/new.html.erb | 5 + app/views/dining_charges/show.html.erb | 4 + app/views/dining_charges/show.json.jbuilder | 1 + config/routes.rb | 1 + db/migrate/20170622050926_create_customers.rb | 2 +- .../20170811052036_create_dining_charges.rb | 16 ++ .../dining_charges_controller_spec.rb | 141 ++++++++++++++++++ spec/helpers/dining_charges_helper_spec.rb | 15 ++ spec/models/dining_charge_spec.rb | 5 + spec/requests/dining_charges_spec.rb | 10 ++ spec/routing/dining_charges_routing_spec.rb | 39 +++++ .../dining_charges/edit.html.erb_spec.rb | 14 ++ .../dining_charges/index.html.erb_spec.rb | 14 ++ .../views/dining_charges/new.html.erb_spec.rb | 14 ++ .../dining_charges/show.html.erb_spec.rb | 11 ++ test/system/dining_charges_test.rb | 9 ++ 26 files changed, 428 insertions(+), 1 deletion(-) create mode 100644 app/assets/javascripts/dining_charges.coffee create mode 100644 app/assets/stylesheets/dining_charges.scss create mode 100644 app/controllers/dining_charges_controller.rb create mode 100644 app/helpers/dining_charges_helper.rb create mode 100644 app/models/dining_charge.rb create mode 100644 app/views/dining_charges/_dining_charge.json.jbuilder create mode 100644 app/views/dining_charges/_form.html.erb create mode 100644 app/views/dining_charges/edit.html.erb create mode 100644 app/views/dining_charges/index.html.erb create mode 100644 app/views/dining_charges/index.json.jbuilder create mode 100644 app/views/dining_charges/new.html.erb create mode 100644 app/views/dining_charges/show.html.erb create mode 100644 app/views/dining_charges/show.json.jbuilder create mode 100644 db/migrate/20170811052036_create_dining_charges.rb create mode 100644 spec/controllers/dining_charges_controller_spec.rb create mode 100644 spec/helpers/dining_charges_helper_spec.rb create mode 100644 spec/models/dining_charge_spec.rb create mode 100644 spec/requests/dining_charges_spec.rb create mode 100644 spec/routing/dining_charges_routing_spec.rb create mode 100644 spec/views/dining_charges/edit.html.erb_spec.rb create mode 100644 spec/views/dining_charges/index.html.erb_spec.rb create mode 100644 spec/views/dining_charges/new.html.erb_spec.rb create mode 100644 spec/views/dining_charges/show.html.erb_spec.rb create mode 100644 test/system/dining_charges_test.rb diff --git a/app/assets/javascripts/dining_charges.coffee b/app/assets/javascripts/dining_charges.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/dining_charges.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/dining_charges.scss b/app/assets/stylesheets/dining_charges.scss new file mode 100644 index 00000000..b0d4ba51 --- /dev/null +++ b/app/assets/stylesheets/dining_charges.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the dining_charges controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/dining_charges_controller.rb b/app/controllers/dining_charges_controller.rb new file mode 100644 index 00000000..7b95af58 --- /dev/null +++ b/app/controllers/dining_charges_controller.rb @@ -0,0 +1,74 @@ +class DiningChargesController < ApplicationController + before_action :set_dining_charge, only: [:show, :edit, :update, :destroy] + + # GET /dining_charges + # GET /dining_charges.json + def index + @dining_charges = DiningCharge.all + end + + # GET /dining_charges/1 + # GET /dining_charges/1.json + def show + end + + # GET /dining_charges/new + def new + @dining_charge = DiningCharge.new + end + + # GET /dining_charges/1/edit + def edit + end + + # POST /dining_charges + # POST /dining_charges.json + def create + @dining_charge = DiningCharge.new(dining_charge_params) + + respond_to do |format| + if @dining_charge.save + format.html { redirect_to @dining_charge, notice: 'Dining charge was successfully created.' } + format.json { render :show, status: :created, location: @dining_charge } + else + format.html { render :new } + format.json { render json: @dining_charge.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /dining_charges/1 + # PATCH/PUT /dining_charges/1.json + def update + respond_to do |format| + if @dining_charge.update(dining_charge_params) + format.html { redirect_to @dining_charge, notice: 'Dining charge was successfully updated.' } + format.json { render :show, status: :ok, location: @dining_charge } + else + format.html { render :edit } + format.json { render json: @dining_charge.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /dining_charges/1 + # DELETE /dining_charges/1.json + def destroy + @dining_charge.destroy + respond_to do |format| + format.html { redirect_to dining_charges_url, notice: 'Dining charge was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_dining_charge + @dining_charge = DiningCharge.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def dining_charge_params + params.fetch(:dining_charge, {}) + end +end diff --git a/app/helpers/dining_charges_helper.rb b/app/helpers/dining_charges_helper.rb new file mode 100644 index 00000000..972a028c --- /dev/null +++ b/app/helpers/dining_charges_helper.rb @@ -0,0 +1,2 @@ +module DiningChargesHelper +end diff --git a/app/models/dining_charge.rb b/app/models/dining_charge.rb new file mode 100644 index 00000000..9a6c5524 --- /dev/null +++ b/app/models/dining_charge.rb @@ -0,0 +1,2 @@ +class DiningCharge < ApplicationRecord +end diff --git a/app/views/dining_charges/_dining_charge.json.jbuilder b/app/views/dining_charges/_dining_charge.json.jbuilder new file mode 100644 index 00000000..045eb7ae --- /dev/null +++ b/app/views/dining_charges/_dining_charge.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! dining_charge, :id, :created_at, :updated_at +json.url dining_charge_url(dining_charge, format: :json) diff --git a/app/views/dining_charges/_form.html.erb b/app/views/dining_charges/_form.html.erb new file mode 100644 index 00000000..0d4232f9 --- /dev/null +++ b/app/views/dining_charges/_form.html.erb @@ -0,0 +1,10 @@ +<%= simple_form_for(@dining_charge) do |f| %> + <%= f.error_notification %> + +
+
+ +
+ <%= f.button :submit %> +
+<% end %> diff --git a/app/views/dining_charges/edit.html.erb b/app/views/dining_charges/edit.html.erb new file mode 100644 index 00000000..042b88d2 --- /dev/null +++ b/app/views/dining_charges/edit.html.erb @@ -0,0 +1,6 @@ +

Editing Dining Charge

+ +<%= render 'form', dining_charge: @dining_charge %> + +<%= link_to 'Show', @dining_charge %> | +<%= link_to 'Back', dining_charges_path %> diff --git a/app/views/dining_charges/index.html.erb b/app/views/dining_charges/index.html.erb new file mode 100644 index 00000000..0b3424ac --- /dev/null +++ b/app/views/dining_charges/index.html.erb @@ -0,0 +1,25 @@ +

<%= notice %>

+ +

Dining Charges

+ + + + + + + + + + <% @dining_charges.each do |dining_charge| %> + + + + + + <% end %> + +
<%= link_to 'Show', dining_charge %><%= link_to 'Edit', edit_dining_charge_path(dining_charge) %><%= link_to 'Destroy', dining_charge, method: :delete, data: { confirm: 'Are you sure?' } %>
+ +
+ +<%= link_to 'New Dining Charge', new_dining_charge_path %> diff --git a/app/views/dining_charges/index.json.jbuilder b/app/views/dining_charges/index.json.jbuilder new file mode 100644 index 00000000..0bb9b37d --- /dev/null +++ b/app/views/dining_charges/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @dining_charges, partial: 'dining_charges/dining_charge', as: :dining_charge diff --git a/app/views/dining_charges/new.html.erb b/app/views/dining_charges/new.html.erb new file mode 100644 index 00000000..9f56e5d3 --- /dev/null +++ b/app/views/dining_charges/new.html.erb @@ -0,0 +1,5 @@ +

New Dining Charge

+ +<%= render 'form', dining_charge: @dining_charge %> + +<%= link_to 'Back', dining_charges_path %> diff --git a/app/views/dining_charges/show.html.erb b/app/views/dining_charges/show.html.erb new file mode 100644 index 00000000..b37298ae --- /dev/null +++ b/app/views/dining_charges/show.html.erb @@ -0,0 +1,4 @@ +

<%= notice %>

+ +<%= link_to 'Edit', edit_dining_charge_path(@dining_charge) %> | +<%= link_to 'Back', dining_charges_path %> diff --git a/app/views/dining_charges/show.json.jbuilder b/app/views/dining_charges/show.json.jbuilder new file mode 100644 index 00000000..a91128e1 --- /dev/null +++ b/app/views/dining_charges/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "dining_charges/dining_charge", dining_charge: @dining_charge diff --git a/config/routes.rb b/config/routes.rb index 0753b64b..12e3f542 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,7 @@ require 'sidekiq/web' Rails.application.routes.draw do + resources :dining_charges root 'home#index' mount Sidekiq::Web => '/kiq' diff --git a/db/migrate/20170622050926_create_customers.rb b/db/migrate/20170622050926_create_customers.rb index 28f38e15..cb370bc1 100644 --- a/db/migrate/20170622050926_create_customers.rb +++ b/db/migrate/20170622050926_create_customers.rb @@ -16,7 +16,7 @@ class CreateCustomers < ActiveRecord::Migration[5.1] t.string :membership_id t.string :membership_type t.string :membership_authentication_code - t.string :customer_type, default => "Dinein" + t.string :customer_type, :default => "Dinein" t.json :tax_profiles end end diff --git a/db/migrate/20170811052036_create_dining_charges.rb b/db/migrate/20170811052036_create_dining_charges.rb new file mode 100644 index 00000000..3a77ad18 --- /dev/null +++ b/db/migrate/20170811052036_create_dining_charges.rb @@ -0,0 +1,16 @@ +class CreateDiningCharges < ActiveRecord::Migration[5.1] + def change + create_table :dining_charges do |t| + t.references :dining_facility + t.string :item_code, :null => false + t.integer :unit_price, :default => 0 + t.boolean :taxable, :default => true + t.string :charge_type, :default => "hr" + t.time :minimum_free_time + t.time :charge_block + t.string :time_rounding, :default => "down" + t.time :time_rounding_block + t.timestamps + end + end +end diff --git a/spec/controllers/dining_charges_controller_spec.rb b/spec/controllers/dining_charges_controller_spec.rb new file mode 100644 index 00000000..2d92fe46 --- /dev/null +++ b/spec/controllers/dining_charges_controller_spec.rb @@ -0,0 +1,141 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe DiningChargesController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # DiningCharge. As you add validations to DiningCharge, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # DiningChargesController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + dining_charge = DiningCharge.create! valid_attributes + get :index, params: {}, session: valid_session + expect(response).to be_success + end + end + + describe "GET #show" do + it "returns a success response" do + dining_charge = DiningCharge.create! valid_attributes + get :show, params: {id: dining_charge.to_param}, session: valid_session + expect(response).to be_success + end + end + + describe "GET #new" do + it "returns a success response" do + get :new, params: {}, session: valid_session + expect(response).to be_success + end + end + + describe "GET #edit" do + it "returns a success response" do + dining_charge = DiningCharge.create! valid_attributes + get :edit, params: {id: dining_charge.to_param}, session: valid_session + expect(response).to be_success + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new DiningCharge" do + expect { + post :create, params: {dining_charge: valid_attributes}, session: valid_session + }.to change(DiningCharge, :count).by(1) + end + + it "redirects to the created dining_charge" do + post :create, params: {dining_charge: valid_attributes}, session: valid_session + expect(response).to redirect_to(DiningCharge.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, params: {dining_charge: invalid_attributes}, session: valid_session + expect(response).to be_success + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested dining_charge" do + dining_charge = DiningCharge.create! valid_attributes + put :update, params: {id: dining_charge.to_param, dining_charge: new_attributes}, session: valid_session + dining_charge.reload + skip("Add assertions for updated state") + end + + it "redirects to the dining_charge" do + dining_charge = DiningCharge.create! valid_attributes + put :update, params: {id: dining_charge.to_param, dining_charge: valid_attributes}, session: valid_session + expect(response).to redirect_to(dining_charge) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + dining_charge = DiningCharge.create! valid_attributes + put :update, params: {id: dining_charge.to_param, dining_charge: invalid_attributes}, session: valid_session + expect(response).to be_success + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested dining_charge" do + dining_charge = DiningCharge.create! valid_attributes + expect { + delete :destroy, params: {id: dining_charge.to_param}, session: valid_session + }.to change(DiningCharge, :count).by(-1) + end + + it "redirects to the dining_charges list" do + dining_charge = DiningCharge.create! valid_attributes + delete :destroy, params: {id: dining_charge.to_param}, session: valid_session + expect(response).to redirect_to(dining_charges_url) + end + end + +end diff --git a/spec/helpers/dining_charges_helper_spec.rb b/spec/helpers/dining_charges_helper_spec.rb new file mode 100644 index 00000000..9592fc0b --- /dev/null +++ b/spec/helpers/dining_charges_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the DiningChargesHelper. For example: +# +# describe DiningChargesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe DiningChargesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/dining_charge_spec.rb b/spec/models/dining_charge_spec.rb new file mode 100644 index 00000000..bc7b0d21 --- /dev/null +++ b/spec/models/dining_charge_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe DiningCharge, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/dining_charges_spec.rb b/spec/requests/dining_charges_spec.rb new file mode 100644 index 00000000..79ac650c --- /dev/null +++ b/spec/requests/dining_charges_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "DiningCharges", type: :request do + describe "GET /dining_charges" do + it "works! (now write some real specs)" do + get dining_charges_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/routing/dining_charges_routing_spec.rb b/spec/routing/dining_charges_routing_spec.rb new file mode 100644 index 00000000..0cf8211b --- /dev/null +++ b/spec/routing/dining_charges_routing_spec.rb @@ -0,0 +1,39 @@ +require "rails_helper" + +RSpec.describe DiningChargesController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/dining_charges").to route_to("dining_charges#index") + end + + it "routes to #new" do + expect(:get => "/dining_charges/new").to route_to("dining_charges#new") + end + + it "routes to #show" do + expect(:get => "/dining_charges/1").to route_to("dining_charges#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/dining_charges/1/edit").to route_to("dining_charges#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/dining_charges").to route_to("dining_charges#create") + end + + it "routes to #update via PUT" do + expect(:put => "/dining_charges/1").to route_to("dining_charges#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/dining_charges/1").to route_to("dining_charges#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/dining_charges/1").to route_to("dining_charges#destroy", :id => "1") + end + + end +end diff --git a/spec/views/dining_charges/edit.html.erb_spec.rb b/spec/views/dining_charges/edit.html.erb_spec.rb new file mode 100644 index 00000000..d91e5fea --- /dev/null +++ b/spec/views/dining_charges/edit.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "dining_charges/edit", type: :view do + before(:each) do + @dining_charge = assign(:dining_charge, DiningCharge.create!()) + end + + it "renders the edit dining_charge form" do + render + + assert_select "form[action=?][method=?]", dining_charge_path(@dining_charge), "post" do + end + end +end diff --git a/spec/views/dining_charges/index.html.erb_spec.rb b/spec/views/dining_charges/index.html.erb_spec.rb new file mode 100644 index 00000000..1712a84f --- /dev/null +++ b/spec/views/dining_charges/index.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "dining_charges/index", type: :view do + before(:each) do + assign(:dining_charges, [ + DiningCharge.create!(), + DiningCharge.create!() + ]) + end + + it "renders a list of dining_charges" do + render + end +end diff --git a/spec/views/dining_charges/new.html.erb_spec.rb b/spec/views/dining_charges/new.html.erb_spec.rb new file mode 100644 index 00000000..91bb8ac2 --- /dev/null +++ b/spec/views/dining_charges/new.html.erb_spec.rb @@ -0,0 +1,14 @@ +require 'rails_helper' + +RSpec.describe "dining_charges/new", type: :view do + before(:each) do + assign(:dining_charge, DiningCharge.new()) + end + + it "renders new dining_charge form" do + render + + assert_select "form[action=?][method=?]", dining_charges_path, "post" do + end + end +end diff --git a/spec/views/dining_charges/show.html.erb_spec.rb b/spec/views/dining_charges/show.html.erb_spec.rb new file mode 100644 index 00000000..e3674b43 --- /dev/null +++ b/spec/views/dining_charges/show.html.erb_spec.rb @@ -0,0 +1,11 @@ +require 'rails_helper' + +RSpec.describe "dining_charges/show", type: :view do + before(:each) do + @dining_charge = assign(:dining_charge, DiningCharge.create!()) + end + + it "renders attributes in

" do + render + end +end diff --git a/test/system/dining_charges_test.rb b/test/system/dining_charges_test.rb new file mode 100644 index 00000000..3ed188c5 --- /dev/null +++ b/test/system/dining_charges_test.rb @@ -0,0 +1,9 @@ +require "application_system_test_case" + +class DiningChargesTest < ApplicationSystemTestCase + # test "visiting the index" do + # visit dining_charges_url + # + # assert_selector "h1", text: "DiningCharge" + # end +end From 3e6ea657f31807021ed60f7fb80e8ea9cab036e5 Mon Sep 17 00:00:00 2001 From: yamin Date: Fri, 11 Aug 2017 14:42:44 +0630 Subject: [PATCH 11/20] Set Footer in Dashboard --- app/views/home/dashboard.html.erb | 44 ++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index 6b49c880..c2074720 100644 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -1,12 +1,12 @@ - -

+
- + <% if current_login_employee.role = "admin" %> + <% elsif current_login_employee.role = "cashier" %> <%= link_to "Cashier Station", origami_path %> - <% elsif current_login_employee = "waiter" %> + <% elsif current_login_employee = "account" %> <%= link_to "Cashier Station", oishi_path %> <% else %> @@ -18,18 +18,30 @@ -
- -
- <%= shop.address %> -
-
- <%= shop.phone_no %> -
- -
+
+
+ + From 79ca1428b9a2ca3f134bc801ef96e179b6a11f2e Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 11 Aug 2017 15:39:08 +0630 Subject: [PATCH 12/20] update close receipt for member discount --- app/controllers/origami/home_controller.rb | 2 +- app/controllers/origami/shifts_controller.rb | 8 ++-- app/models/printer/cashier_station_printer.rb | 4 +- app/models/shift_sale.rb | 6 +++ app/pdf/close_cashier_pdf.rb | 31 +++++++++++-- app/views/origami/home/index.html.erb | 2 +- .../origami/shifts/sale_summary.html.erb | 45 +++++++++++++------ 7 files changed, 74 insertions(+), 24 deletions(-) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 2e8aba2c..27822a17 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -7,6 +7,7 @@ class Origami::HomeController < BaseOrigamiController @complete = Sale.where("sale_status != 'new'") @orders = Order.all.order('date desc') @shop = Shop.find_by_id(1) + # @shift = ShiftSale.current_open_shift(current_user.id) end @@ -39,7 +40,6 @@ class Origami::HomeController < BaseOrigamiController else sale = Sale.find(booking.sale_id) if sale.sale_status != "completed" && sale.sale_status != 'void' - puts "enter" @sale_array.push(sale) if @status_order == 'order' @status_order = 'sale' diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index afb28714..e134a594 100644 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -39,13 +39,13 @@ class Origami::ShiftsController < BaseOrigamiController # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') - + @total_member_discount = ShiftSale.get_total_member_discount(@shift) # get printer info - print_settings=PrintSetting.find_by_unique_code(unique_code) + print_settings = PrintSetting.find_by_unique_code(unique_code) printer = Printer::CashierStationPrinter.new(print_settings) - printer.print_close_cashier(print_settings,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account) + printer.print_close_cashier(print_settings,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount) end @@ -72,6 +72,8 @@ class Origami::ShiftsController < BaseOrigamiController # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') + @total_member_discount = ShiftSale.get_total_member_discount(@shift) + end end diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index b7bc34ae..91100145 100644 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -22,14 +22,14 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # end #Bill Receipt Print - def print_close_cashier(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount) + def print_close_cashier(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount) #Use CUPS service #Generate PDF #Print cashier = shift_sale.employee.name shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") - pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount) + pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount) filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" pdf.render_file filename self.print(filename) diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 8a8c1469..168e63ff 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -125,6 +125,12 @@ class ShiftSale < ApplicationRecord query = query.where("sales.shift_sale_id =? and sale_status = 'completed'", shift.id) .group("acc.title").order("acc.id") end + end + + def self.get_total_member_discount(shift) + query = Sale.select("SUM(sales.total_discount) as member_discount") + .where("shift_sale_id =? and sale_status = 'completed' and discount_type = 'member_discount'", shift.id) + end end diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 1955bf74..51f905d6 100644 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -1,6 +1,6 @@ class CloseCashierPdf < Prawn::Document attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width - def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account) + def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount) self.page_width = 210 self.page_height = 7000 self.margin = 5 @@ -32,7 +32,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount) @@ -51,7 +51,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule end - def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account) + def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount) move_down 7 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -277,9 +277,32 @@ class CloseCashierPdf < Prawn::Document end #end total amount by Account + if total_member_discount[0].member_discount.present? + @member_discount = total_member_discount[0].member_discount rescue 0.0 + @overall = shift_sale.total_discounts - @member_discount + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Member Discount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{@member_discount}", :size => self.item_font_size, :align => :right + end + else + @overall = shift_sale.total_discounts + end + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Overall Discount Amount :", :size => self.item_font_size, :align => :right + text "Total Overall Discount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{@overall}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Discount Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{shift_sale.total_discounts}", :size => self.item_font_size, :align => :right diff --git a/app/views/origami/home/index.html.erb b/app/views/origami/home/index.html.erb index cdb76bd0..e3193a98 100644 --- a/app/views/origami/home/index.html.erb +++ b/app/views/origami/home/index.html.erb @@ -108,7 +108,7 @@ - <%if current_login_employee.role == "cashier" %> + <%if current_login_employee.role == "cashier" && @shop.quick_sale_summary == true%> <%end%> diff --git a/app/views/origami/shifts/sale_summary.html.erb b/app/views/origami/shifts/sale_summary.html.erb index c552d6b0..94e59924 100644 --- a/app/views/origami/shifts/sale_summary.html.erb +++ b/app/views/origami/shifts/sale_summary.html.erb @@ -55,11 +55,29 @@ <%= amount.total_price.round(2) %> <%end%> + + <% if !@total_member_discount[0].member_discount.nil? + @member_discount = @total_member_discount[0].member_discount rescue 0.0 + @overall = @shift.total_discounts - @member_discount + %> - - Overall Discount Amount - <%= @shift.total_discounts %> + + Total Member Discount + <%= @member_discount %> + <%else @overall = @shift.total_discounts %> + + <%end%> + + + Total Overall Discount + <%= @overall %> + + + + Total Discount + <%= @shift.total_discounts %> + <% @sale_taxes.each do |tax| %> @@ -98,6 +116,7 @@ <%=@shift.credit_sales %> <% @total_amount = 0 + @other_payment.each do |other| %> @@ -107,32 +126,32 @@ MPU Payment - <%=other.mpu_amount.round(2) %> - <% @total_amount = @total_amount+other.mpu_amount %> + <%=other.mpu_amount.round(2) rescue 0.0 %> + <% @total_amount = @total_amount+other.mpu_amount rescue 0.0 %> VISA Payment - <%=other.visa_amount.round(2) %> - <% @total_amount = @total_amount+other.visa_amount %> + <%=other.visa_amount.round(2) rescue 0.0 %> + <% @total_amount = @total_amount+other.visa_amount rescue 0.0 %> JCB Payment - <%=other.master_amount.round(2) %> - <% @total_amount = @total_amount+other.master_amount %> + <%=other.master_amount.round(2) rescue 0.0 %> + <% @total_amount = @total_amount+other.master_amount rescue 0.0 %> Master Payment - <%=other.jcb_amount.round(2) %> - <% @total_amount = @total_amount+other.jcb_amount %> + <%=other.jcb_amount.round(2) rescue 0.0 %> + <% @total_amount = @total_amount+other.jcb_amount rescue 0.0 %> Reedem Payment - <%=other.paypar_amount.round(2) %> - <% @total_amount = @total_amount+other.paypar_amount %> + <%=other.paypar_amount.round(2) rescue 0.0 %> + <% @total_amount = @total_amount+other.paypar_amount rescue 0.0 %> <%end%> From 10aae022d23730964ecc484d086dc2510c319f5d Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 11 Aug 2017 16:47:57 +0630 Subject: [PATCH 13/20] update oqs --- app/assets/javascripts/OQS.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 19d0429e..801fd214 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -25,11 +25,12 @@ $(document).ready(function(){ // }, 10000); $(".nav-completed").on("click", function(){ $("#completed").removeClass('hide') - + $(".oqs_append").addClass('hide') }); $(".oqs_click").on("click", function(){ $("#completed").addClass('hide') + $(".oqs_append").removeClass('hide') var oqs_id = $(this).find(".oqs-id").text(); var url = 'oqs/get_items/'+oqs_id; show_details(url); From 740038757d39326632a81f95313a29d2afec511b Mon Sep 17 00:00:00 2001 From: Phyo Date: Fri, 11 Aug 2017 17:53:48 +0630 Subject: [PATCH 14/20] Dining Charges CRUD --- .../dining_charges_controller.rb | 29 +++++++++++++++---- app/models/dining_charge.rb | 2 ++ app/models/dining_facility.rb | 1 + app/views/dining_charges/_form.html.erb | 10 ------- app/views/dining_charges/edit.html.erb | 6 ---- app/views/dining_charges/new.html.erb | 5 ---- .../_dining_charge.json.jbuilder | 0 .../settings/dining_charges/_form.html.erb | 18 ++++++++++++ .../settings/dining_charges/edit.html.erb | 19 ++++++++++++ .../dining_charges/index.html.erb | 0 .../dining_charges/index.json.jbuilder | 0 .../settings/dining_charges/new.html.erb | 18 ++++++++++++ .../dining_charges/show.html.erb | 0 .../dining_charges/show.json.jbuilder | 0 app/views/settings/tables/_form.html.erb | 20 +++++++++++++ config/routes.rb | 10 +++++-- 16 files changed, 108 insertions(+), 30 deletions(-) rename app/controllers/{ => settings}/dining_charges_controller.rb (61%) delete mode 100644 app/views/dining_charges/_form.html.erb delete mode 100644 app/views/dining_charges/edit.html.erb delete mode 100644 app/views/dining_charges/new.html.erb rename app/views/{ => settings}/dining_charges/_dining_charge.json.jbuilder (100%) create mode 100644 app/views/settings/dining_charges/_form.html.erb create mode 100644 app/views/settings/dining_charges/edit.html.erb rename app/views/{ => settings}/dining_charges/index.html.erb (100%) rename app/views/{ => settings}/dining_charges/index.json.jbuilder (100%) create mode 100644 app/views/settings/dining_charges/new.html.erb rename app/views/{ => settings}/dining_charges/show.html.erb (100%) rename app/views/{ => settings}/dining_charges/show.json.jbuilder (100%) diff --git a/app/controllers/dining_charges_controller.rb b/app/controllers/settings/dining_charges_controller.rb similarity index 61% rename from app/controllers/dining_charges_controller.rb rename to app/controllers/settings/dining_charges_controller.rb index 7b95af58..6de504bf 100644 --- a/app/controllers/dining_charges_controller.rb +++ b/app/controllers/settings/dining_charges_controller.rb @@ -1,6 +1,7 @@ -class DiningChargesController < ApplicationController +class Settings::DiningChargesController < ApplicationController before_action :set_dining_charge, only: [:show, :edit, :update, :destroy] - + before_action :set_settings_facility + before_action :set_settings_zone # GET /dining_charges # GET /dining_charges.json def index @@ -25,10 +26,10 @@ class DiningChargesController < ApplicationController # POST /dining_charges.json def create @dining_charge = DiningCharge.new(dining_charge_params) - + @dining_charge.dining_facility_id = @settings_dining_facility.id respond_to do |format| if @dining_charge.save - format.html { redirect_to @dining_charge, notice: 'Dining charge was successfully created.' } + format.html { redirect_to edit_settings_zone_table_path(@zone,@settings_dining_facility), notice: 'Dining charge was successfully created.' } format.json { render :show, status: :created, location: @dining_charge } else format.html { render :new } @@ -41,8 +42,9 @@ class DiningChargesController < ApplicationController # PATCH/PUT /dining_charges/1.json def update respond_to do |format| + @dining_charge.dining_facility_id = @settings_dining_facility.id if @dining_charge.update(dining_charge_params) - format.html { redirect_to @dining_charge, notice: 'Dining charge was successfully updated.' } + format.html { redirect_to edit_settings_zone_table_path(@zone,@settings_dining_facility), notice: 'Dining charge was successfully updated.' } format.json { render :show, status: :ok, location: @dining_charge } else format.html { render :edit } @@ -67,8 +69,23 @@ class DiningChargesController < ApplicationController @dining_charge = DiningCharge.find(params[:id]) end + def set_settings_facility + if params[:table_id] + @table = true + @settings_dining_facility = Table.find(params[:table_id]) + elsif params[:room_id] + @room = true + @settings_dining_facility = Room.find(params[:room_id]) + end + end + + def set_settings_zone + @zone = Zone.find(params[:zone_id]) + end + # Never trust parameters from the scary internet, only allow the white list through. def dining_charge_params - params.fetch(:dining_charge, {}) + # params.fetch(:dining_charge, {}) + params.require(:dining_charge).permit(:item_code, :unit_price, :taxable, :charge_type,:minimum_free_time ,:charge_block,:time_rounding,:time_rounding_block, :zone_id) end end diff --git a/app/models/dining_charge.rb b/app/models/dining_charge.rb index 9a6c5524..0c52811f 100644 --- a/app/models/dining_charge.rb +++ b/app/models/dining_charge.rb @@ -1,2 +1,4 @@ class DiningCharge < ApplicationRecord + belongs_to :table + belongs_to :room end diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 510da53d..f441612a 100644 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -1,5 +1,6 @@ class DiningFacility < ApplicationRecord belongs_to :zone + has_many :dining_charges TABLE_TYPE = "Table" ROOM_TYPE = "Room" diff --git a/app/views/dining_charges/_form.html.erb b/app/views/dining_charges/_form.html.erb deleted file mode 100644 index 0d4232f9..00000000 --- a/app/views/dining_charges/_form.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -<%= simple_form_for(@dining_charge) do |f| %> - <%= f.error_notification %> - -
-
- -
- <%= f.button :submit %> -
-<% end %> diff --git a/app/views/dining_charges/edit.html.erb b/app/views/dining_charges/edit.html.erb deleted file mode 100644 index 042b88d2..00000000 --- a/app/views/dining_charges/edit.html.erb +++ /dev/null @@ -1,6 +0,0 @@ -

Editing Dining Charge

- -<%= render 'form', dining_charge: @dining_charge %> - -<%= link_to 'Show', @dining_charge %> | -<%= link_to 'Back', dining_charges_path %> diff --git a/app/views/dining_charges/new.html.erb b/app/views/dining_charges/new.html.erb deleted file mode 100644 index 9f56e5d3..00000000 --- a/app/views/dining_charges/new.html.erb +++ /dev/null @@ -1,5 +0,0 @@ -

New Dining Charge

- -<%= render 'form', dining_charge: @dining_charge %> - -<%= link_to 'Back', dining_charges_path %> diff --git a/app/views/dining_charges/_dining_charge.json.jbuilder b/app/views/settings/dining_charges/_dining_charge.json.jbuilder similarity index 100% rename from app/views/dining_charges/_dining_charge.json.jbuilder rename to app/views/settings/dining_charges/_dining_charge.json.jbuilder diff --git a/app/views/settings/dining_charges/_form.html.erb b/app/views/settings/dining_charges/_form.html.erb new file mode 100644 index 00000000..47801ef6 --- /dev/null +++ b/app/views/settings/dining_charges/_form.html.erb @@ -0,0 +1,18 @@ +<%= simple_form_for([:settings,@zone,@settings_dining_facility,@dining_charge]) do |f| %> + <%= f.error_notification %> + +
+ <%= f.input :item_code %> + <%= f.input :unit_price %> + <%= f.input :taxable %> + <%= f.input :charge_type %> + <%= f.input :minimum_free_time %> + <%= f.input :charge_block %> + <%= f.input :time_rounding %> + <%= f.input :time_rounding_block %> +
+ +
+ <%= f.button :submit %> +
+<% end %> diff --git a/app/views/settings/dining_charges/edit.html.erb b/app/views/settings/dining_charges/edit.html.erb new file mode 100644 index 00000000..1b0eb406 --- /dev/null +++ b/app/views/settings/dining_charges/edit.html.erb @@ -0,0 +1,19 @@ + + +
+ + <%= render 'form', dining_charge: @dining_charge %> +
diff --git a/app/views/dining_charges/index.html.erb b/app/views/settings/dining_charges/index.html.erb similarity index 100% rename from app/views/dining_charges/index.html.erb rename to app/views/settings/dining_charges/index.html.erb diff --git a/app/views/dining_charges/index.json.jbuilder b/app/views/settings/dining_charges/index.json.jbuilder similarity index 100% rename from app/views/dining_charges/index.json.jbuilder rename to app/views/settings/dining_charges/index.json.jbuilder diff --git a/app/views/settings/dining_charges/new.html.erb b/app/views/settings/dining_charges/new.html.erb new file mode 100644 index 00000000..1caba288 --- /dev/null +++ b/app/views/settings/dining_charges/new.html.erb @@ -0,0 +1,18 @@ + +
+ + <%= render 'form', dining_charge: @dining_charge %> +
diff --git a/app/views/dining_charges/show.html.erb b/app/views/settings/dining_charges/show.html.erb similarity index 100% rename from app/views/dining_charges/show.html.erb rename to app/views/settings/dining_charges/show.html.erb diff --git a/app/views/dining_charges/show.json.jbuilder b/app/views/settings/dining_charges/show.json.jbuilder similarity index 100% rename from app/views/dining_charges/show.json.jbuilder rename to app/views/settings/dining_charges/show.json.jbuilder diff --git a/app/views/settings/tables/_form.html.erb b/app/views/settings/tables/_form.html.erb index 169e1601..3d641592 100644 --- a/app/views/settings/tables/_form.html.erb +++ b/app/views/settings/tables/_form.html.erb @@ -7,6 +7,26 @@ <%= f.input :seater %> <%= f.input :order_by %> <%= f.input :is_active %> + <% if @settings_table.dining_charges.length == 0 %> +
+
+ <%= link_to 'Add For Extra Charges', new_settings_zone_table_dining_charge_path(@zone,@settings_table),:class => 'btn btn-primary' %> +
+
+ <% else %> + <% @settings_table.dining_charges.each do |dc| %> +
+
Dining Charge
+
item code : <%= dc.item_code %>
+
Unit price : <%= dc.unit_price %>
+
Charge type : <%= dc.charge_type %>
+
+ <%= link_to 'Edit Charges', edit_settings_zone_table_dining_charge_path(@zone,@settings_table,dc),:class => 'btn btn-primary' %> + +
+
+ <% end %> + <% end %>
diff --git a/config/routes.rb b/config/routes.rb index 12e3f542..b6af8698 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,7 +2,6 @@ require 'sidekiq/web' Rails.application.routes.draw do - resources :dining_charges root 'home#index' mount Sidekiq::Web => '/kiq' @@ -146,6 +145,7 @@ Rails.application.routes.draw do get 'sale/:sale_id/payment/others_payment/Master' => "master#index" get 'sale/:sale_id/payment/others_payment/JCB' => "jcb#index" get 'sale/:sale_id/payment/others_payment/Redeem' => "redeem_payments#index" + get 'sale/:sale_id/payment/others_payment/Voucher' => "voucher#index" #---------Void --------------# post 'sale/:sale_id/void' => 'void#overall_void' @@ -254,9 +254,13 @@ Rails.application.routes.draw do #zones resources :zones do #tables - resources :tables + resources :tables do + resources :dining_charges + end #rooms - resources :rooms + resources :rooms do + resources :dining_charges + end end end From 5c2928166d0bc720303ab88f41b43c3bec00fd6f Mon Sep 17 00:00:00 2001 From: Phyo Date: Fri, 11 Aug 2017 18:10:57 +0630 Subject: [PATCH 15/20] Voucher/Cuopon UI phrase 1 --- app/controllers/origami/voucher_controller.rb | 32 ++++ .../origami/voucher/create.json.jbuilder | 5 + app/views/origami/voucher/index.html.erb | 169 ++++++++++++++++++ lib/tasks/menu_osaka.rake | 1 + 4 files changed, 207 insertions(+) create mode 100644 app/controllers/origami/voucher_controller.rb create mode 100644 app/views/origami/voucher/create.json.jbuilder create mode 100644 app/views/origami/voucher/index.html.erb diff --git a/app/controllers/origami/voucher_controller.rb b/app/controllers/origami/voucher_controller.rb new file mode 100644 index 00000000..a9bdcc2b --- /dev/null +++ b/app/controllers/origami/voucher_controller.rb @@ -0,0 +1,32 @@ +class Origami::VoucherController < BaseOrigamiController + + def index + @sale_id = params[:sale_id] + + # limit voucher_amount + sale_data = Sale.find_by_sale_id(@sale_id) + total = sale_data.grand_total + @vouchercount = 0 + others = 0 + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "voucher" + @vouchercount = @vouchercount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_voucher = total - @vouchercount - others + + end + + def create + cash = params[:amount] + sale_id = params[:sale_id] + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + sale_payment = SalePayment.new + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "voucher") + end + end + +end diff --git a/app/views/origami/voucher/create.json.jbuilder b/app/views/origami/voucher/create.json.jbuilder new file mode 100644 index 00000000..9767a7d8 --- /dev/null +++ b/app/views/origami/voucher/create.json.jbuilder @@ -0,0 +1,5 @@ +if(@status) + json.status @status +else + json.status false +end diff --git a/app/views/origami/voucher/index.html.erb b/app/views/origami/voucher/index.html.erb new file mode 100644 index 00000000..809793ce --- /dev/null +++ b/app/views/origami/voucher/index.html.erb @@ -0,0 +1,169 @@ + +
+ +
+
+
+

Voucher / Coupon

+
+
+
+
+
+
+ + +
+
+
+ <% if @vouchercount != 0 %> +
+
+ + +
+
+
+ <% end %> +
+
+ + +
+
+
+
+
+ +
0.0
+
+
+
+
+
+
+ +
+ +
+
+
+
1
+
2
+
3
+
+
+
4
+
5
+
6
+
+
+
7
+
8
+
9
+
+
+
0
+
.
+
00
+
+
+
Nett
+
Del
+
Clr
+
+
+
+
+
1000
+
3000
+
+
+
5000
+
10000
+
+
+
Pay
+
+
+
+ +
+ +
+ +
+
+ + diff --git a/lib/tasks/menu_osaka.rake b/lib/tasks/menu_osaka.rake index 0acc4a1e..117fdb5c 100644 --- a/lib/tasks/menu_osaka.rake +++ b/lib/tasks/menu_osaka.rake @@ -1224,6 +1224,7 @@ payment_methods = PaymentMethodSetting.create({payment_method:"VISA",gateway_url payment_methods = PaymentMethodSetting.create({payment_method:"JCB",gateway_url: "http://staging.membership.paypar.ws"}) payment_methods = PaymentMethodSetting.create({payment_method:"Master",gateway_url: "http://staging.membership.paypar.ws"}) payment_methods = PaymentMethodSetting.create({payment_method:"Redeem",gateway_url: "http://staging.membership.paypar.ws",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv"}) +payment_methods = PaymentMethodSetting.create({payment_method:"Voucher",gateway_url: "http://staging.membership.paypar.ws",merchant_account_id:"RxzaYyAGzm7VqAZ4hKnv"}) #Default Order Queue stations order_queue_station1 = OrderQueueStation.create({station_name: "K1", is_active: true,printer_name: "Cashier", processing_items: JSON.generate(['I0001','I0002','I0003','I0004']), print_copy:false, cut_per_item: false, use_alternate_name: false, created_by: "SYSTEM DEFAULT"}) From 6f39a024cae8ddd88a83ce9a3739a54b03a0f435 Mon Sep 17 00:00:00 2001 From: Nweni Date: Mon, 14 Aug 2017 11:30:58 +0630 Subject: [PATCH 16/20] dining charge --- app/models/dining_charge.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/app/models/dining_charge.rb b/app/models/dining_charge.rb index 9a6c5524..4aa47c6d 100644 --- a/app/models/dining_charge.rb +++ b/app/models/dining_charge.rb @@ -1,2 +1,39 @@ class DiningCharge < ApplicationRecord + + def amount_calculate(dining_charges_obj, checkin , checkout) + + if !checkin.nil? && !checkout.nil? && !dining_charges_obj.nil? + + minutes = ((checkin - checkout) * 24 * 60).to_i # stay minutes + dining_minutes = minutes - dining_charges_obj.minimum_free_time # stayminutes - free minutes + charge_type = dining_charges_obj.charge_type + if charge_type == 'hr' + + elsif charge_type == 'day' + price = charge_by_day + end + end + + end + + def charge_by_hour + + end + + def charge_by_day(chargesObj, dining_minutes) + minues_per_day = 12 * 60 + result = dining_minutes / minues_per_day + if result < 1 + return chargesObj.unit_price + elsif result > 1 + solid_price = result * chargesObj.unit_price + + remain_value = dining_minutes % minues_per_day + roundingblock = remain_value / chargesObj.time_rounding_block + if roundingblock > 1 + + end + end + end + end From 25ab7c9701eef0b883d9e46dc30a45dbbb026979 Mon Sep 17 00:00:00 2001 From: Phyo Date: Mon, 14 Aug 2017 13:41:18 +0630 Subject: [PATCH 17/20] Payment Voucher UI fix --- app/controllers/origami/voucher_controller.rb | 46 +++++++++++++++++-- app/views/origami/voucher/index.html.erb | 36 +++++++++------ config/routes.rb | 1 + 3 files changed, 67 insertions(+), 16 deletions(-) diff --git a/app/controllers/origami/voucher_controller.rb b/app/controllers/origami/voucher_controller.rb index a9bdcc2b..7eda6084 100644 --- a/app/controllers/origami/voucher_controller.rb +++ b/app/controllers/origami/voucher_controller.rb @@ -22,10 +22,50 @@ class Origami::VoucherController < BaseOrigamiController def create cash = params[:amount] sale_id = params[:sale_id] + sale_id = params[:refnumber] if(Sale.exists?(sale_id)) - saleObj = Sale.find(sale_id) - sale_payment = SalePayment.new - @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "voucher") + customer_data= Customer.find_by_customer_id(sale_data.customer_id) + if customer_data + membership_id = customer_data.membership_id + membership_setting = MembershipSetting.find_by_membership_type("paypar_url") + if membership_setting.gateway_url + member_actions =MembershipAction.find_by_membership_type("get_account_balance") #need to modify here + if member_actions.gateway_url + campaign_type_id = member_actions.additional_parameter["campaign_type_id"] + url = membership_setting.gateway_url.to_s + member_actions.gateway_url.to_s + merchant_uid= member_actions.merchant_account_id + auth_token = member_actions.auth_token.to_s + # membership_data = SalePayment.get_paypar_account(url,membership_setting.auth_token,@membership_id,@campaign_type_id,merchant_uid,auth_token) + # if membership_data["status"]==true + begin + response = HTTParty.get(url, + :body => { app_token: token,membership_id:membership_id, + campaign_type_id:campaign_type_id,merchant_uid:merchant_uid, + auth_token:auth_token + }.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }, :timeout => 10 + ) + rescue Net::OpenTimeout + response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} + end + # end + end + end + end + if( response["status"]==true ) + saleObj = Sale.find(sale_id) + sale_payment = SalePayment.new + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "voucher") + end end end diff --git a/app/views/origami/voucher/index.html.erb b/app/views/origami/voucher/index.html.erb index 809793ce..db4de245 100644 --- a/app/views/origami/voucher/index.html.erb +++ b/app/views/origami/voucher/index.html.erb @@ -28,14 +28,15 @@
- +

-
0.0
+ +

@@ -103,12 +104,17 @@ $(document).ready(function() { } }); // number key pad +var float_value = "" +var total = 0 + +$(document).on('focusout', '.float-value', function(event){ + float_value = $(this).attr("data-value"); $(document).on('click', '.cashier_number', function(event){ event.stopPropagation(); event.preventDefault(); if(event.handled !== true) { var original_value; - original_value = $('#amount').text(); + original_value = $('#'+float_value).val(); var input_value = $(this).attr("data-value"); @@ -116,28 +122,28 @@ $(document).on('click', '.cashier_number', function(event){ switch (input_type) { case 'num': if (original_value == "0.0"){ - $('#amount').text(input_value); + $('#'+float_value).val(input_value); }else{ - $('#amount').append(input_value); + $('#'+float_value).val(original_value+input_value); } break; case 'add': var input_value = $(this).attr("data-value"); amount = parseInt(input_value) + parseInt(original_value); - $('#amount').html(amount); + $('#'+float_value).val(amount); break; case 'clr': - $('#amount').html("0.0"); + $('#'+float_value).val("0.0"); break; case 'del' : - var cash=$('#amount').text(); - $('#amount').text(cash.substr(0,cash.length-1)); + var cash=$('#'+float_value).val(); + $('#'+float_value).val(cash.substr(0,cash.length-1)); break; case 'nett': var remain_amount = $('#validamount').val(); - $('#amount').text(remain_amount); + $('#'+float_value).val(remain_amount); break; } @@ -146,15 +152,19 @@ $(document).on('click', '.cashier_number', function(event){ return false; } }); +}) $('#voucher_pay').on('click',function(){ - var amount = $('#amount').text(); + var amount = $('#amount').val(); + var refnumber = $("#<%=@sale_id %>").val(); var sale_id = "<%= @sale_id %>"; if(parseFloat(amount) <= parseFloat($("#validamount").attr("value")) ){ + // alert(amount); + // alert(refnumber); $.ajax({type: "POST", - url: "<%= origami_payment_jcb_path %>", - data: "amount="+ amount + "&sale_id="+ sale_id, + url: "<%= origami_payment_voucher_path %>", + data: "amount="+ amount + "&sale_id="+ sale_id+ "&refnumber="+ refnumber, success:function(result){ if(result){ alert("Payment success") diff --git a/config/routes.rb b/config/routes.rb index b6af8698..9e62023c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -137,6 +137,7 @@ Rails.application.routes.draw do post 'payment/visa' => "visa#create" post 'payment/paypar' => 'paypar_payments#create' post 'payment/credit' => 'credit_payments#create' + post 'payment/voucher' => 'voucher_payments#create' get 'sale/:sale_id/payment/credit_payment' => "credit_payments#index" get 'sale/:sale_id/payment/others_payment' => "others_payments#index" From 069ad167332add09bc2d7266e9605385883186cf Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 14 Aug 2017 13:42:47 +0630 Subject: [PATCH 18/20] update oqs filtring --- app/assets/javascripts/OQS.js | 8 ++-- app/controllers/oqs/home_controller.rb | 49 +++++++++++++++++++----- app/views/oqs/home/index.html.erb | 52 ++++++++++++++++++++------ 3 files changed, 84 insertions(+), 25 deletions(-) diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 801fd214..5ed26997 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -31,8 +31,9 @@ $(document).ready(function(){ $(".oqs_click").on("click", function(){ $("#completed").addClass('hide') $(".oqs_append").removeClass('hide') + var oqs_id = $(this).find(".oqs-id").text(); - var url = 'oqs/get_items/'+oqs_id; + var url = 'oqs/get_items/'+oqs_id; show_details(url); }); //End Click @@ -40,15 +41,14 @@ $(document).ready(function(){ function show_details(url){ var oqs_append = $('.oqs_append'); oqs_append.empty(); - + var filter = $('.filter').text(); //Start Ajax $.ajax({ type: "GET", url: url, - data: {}, + data: {'filter':filter}, dataType: "json", success: function(data) { - for(var field in data) { var price = parseFloat(data[field].price).toFixed(2); diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index dfe648d0..dae8b02f 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -7,7 +7,17 @@ class Oqs::HomeController < BaseOqsController # @queue_items_details = queue_items_query(false) # Query for OQS with delivery status true - @queue_completed_item = completed_order + + + @filter = params[:filter] + + @queue_completed_item = completed_order(@filter) + if !@filter.nil? + @count = queue_items_count_query(false,@filter) + @count.each do |count| + + end + end # @queue_stations_items=Array.new @@ -71,7 +81,8 @@ class Oqs::HomeController < BaseOqsController def get_items_by_oqs oqs_id = params[:id] - items = queue_items_query(false,oqs_id) + filter = params[:filter] + items = queue_items_query(false,oqs_id,filter) render :json => items.to_json end @@ -96,13 +107,14 @@ class Oqs::HomeController < BaseOqsController # Query for OQS with delivery status - def queue_items_query(status,oqs_id=nil) + def queue_items_query(status,oqs_id=nil,filter) if oqs_id == nil oqs = '' else oqs = "and assigned_order_items.order_queue_station_id = '#{oqs_id}' " end - AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, + + query = AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type as table_type, @@ -117,14 +129,15 @@ class Oqs::HomeController < BaseOqsController left join booking_orders as bo on bo.order_id = assigned_order_items.order_id left join bookings as bk on bk.booking_id = bo.booking_id left join dining_facilities as df on df.id = bk.dining_facility_id") - .where("assigned_order_items.delivery_status = #{status} AND odt.price <> 0 AND assigned_order_items.created_at >= '#{Time.now.beginning_of_day.utc}' #{oqs}") + .where("assigned_order_items.delivery_status = #{status} AND odt.price <> 0 AND assigned_order_items.created_at >= '#{Time.now.beginning_of_day.utc}' #{oqs} ") + query = query.where("df.name LIKE ? OR odt.order_id LIKE ? OR odt.item_name LIKE ? OR cus.name = '#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%",) .group("assigned_order_items.assigned_order_item_id") end # Completed Order - def completed_order - AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") + def completed_order(filter) + query = AssignedOrderItem.select("assigned_order_items.assigned_order_item_id, oqs.id as station_id, oqs.station_name, oqs.is_active, oqpz.zone_id, df.name as zone, df.type, odt.order_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.options, cus.name as customer_name, odt.created_at") .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id left join order_queue_process_by_zones as oqpz on oqpz.order_queue_station_id = oqs.id left join orders as od ON od.order_id = assigned_order_items.order_id @@ -134,12 +147,28 @@ class Oqs::HomeController < BaseOqsController left join bookings as bk on bk.booking_id = bo.booking_id left join dining_facilities as df on df.id = bk.dining_facility_id") .where("assigned_order_items.delivery_status = true AND odt.price <> 0 AND assigned_order_items.created_at between '#{Time.now.beginning_of_day.utc}' and '#{Time.now.end_of_day.utc}'") - .group("assigned_order_items.order_id") - .limit(20) - .order("assigned_order_items.created_at") + query = query.where("df.name LIKE ? OR odt.order_id LIKE ? OR odt.item_name LIKE ? OR cus.name = '#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%",) + .group("assigned_order_items.order_id") + .limit(20) + .order("assigned_order_items.created_at") # completed_order = AssignedOrderItem.group(:order_id).where('delivery_status=true'); end + def queue_items_count_query(status,filter) + query = AssignedOrderItem.select("count(odt.item_code) as total,oqs.id as station_id") + .joins(" left join order_queue_stations as oqs on oqs.id = assigned_order_items.order_queue_station_id + left join orders as od ON od.order_id = assigned_order_items.order_id + left join order_items as odt ON odt.item_code = assigned_order_items.item_code AND odt.order_id = assigned_order_items.order_id + left join customers as cus ON cus.customer_id = od.customer_id + left join booking_orders as bo on bo.order_id = assigned_order_items.order_id + left join bookings as bk on bk.booking_id = bo.booking_id + left join dining_facilities as df on df.id = bk.dining_facility_id") + .where("assigned_order_items.delivery_status = #{status} AND odt.price <> 0 AND assigned_order_items.created_at >= '#{Time.now.beginning_of_day.utc}' ") + query = query.where("df.name LIKE ? OR odt.order_id LIKE ? OR odt.item_name LIKE ? OR cus.name = '#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%",) + .group("oqs.id") + + end + end diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 3ab1cf24..81e14467 100644 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -1,10 +1,26 @@
- +
+ <%= form_tag oqs_root_path, :method => :get do %> +
+ +
+ +
+ +
+<% end %> +
+
+ +
+ \ No newline at end of file From 497a1b60f713fa1dd5022b85f31dc68d74bad657 Mon Sep 17 00:00:00 2001 From: Phyo Date: Mon, 14 Aug 2017 14:04:39 +0630 Subject: [PATCH 19/20] add Updated_at to Employee Listing --- app/views/settings/employees/index.html.erb | 2 ++ app/views/settings/employees/show.html.erb | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/views/settings/employees/index.html.erb b/app/views/settings/employees/index.html.erb index b44a2dcd..7c1f2eb7 100644 --- a/app/views/settings/employees/index.html.erb +++ b/app/views/settings/employees/index.html.erb @@ -16,6 +16,7 @@ Name Role Created At + Updated At Action @@ -26,6 +27,7 @@ <%= link_to employee.name,settings_employee_path(employee) %> <%= employee.role %> <%= employee.created_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %> + <%= employee.updated_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %> <%= link_to 'Edit', edit_settings_employee_path(employee) %> <%if employee.role != "administrator"%> diff --git a/app/views/settings/employees/show.html.erb b/app/views/settings/employees/show.html.erb index cad7a6ad..1869fcde 100644 --- a/app/views/settings/employees/show.html.erb +++ b/app/views/settings/employees/show.html.erb @@ -2,7 +2,7 @@ @@ -15,7 +15,8 @@ Name Role - + Created At + Updated At Action @@ -24,6 +25,8 @@ <%= @employee.name %> <%= @employee.role %> + <%= @employee.created_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %> + <%= @employee.updated_at.utc.getlocal.strftime("%Y-%m-%d/%I:%M %p") %> <%= link_to 'Edit', edit_settings_employee_path(@employee) %> @@ -34,4 +37,3 @@
- From 5a5e654dbcb78db75e995e06683e940d5894371b Mon Sep 17 00:00:00 2001 From: Yan Date: Mon, 14 Aug 2017 15:26:04 +0630 Subject: [PATCH 20/20] move css to css file --- app/assets/stylesheets/settings.scss | 17 ++++++++++++++++- app/views/home/dashboard.html.erb | 5 ----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/settings.scss b/app/assets/stylesheets/settings.scss index 37064f07..ba6ba39d 100644 --- a/app/assets/stylesheets/settings.scss +++ b/app/assets/stylesheets/settings.scss @@ -26,7 +26,22 @@ ul.dropdown-menu li a{ background-color: transparent !important; margin-bottom: 0px !important; } + .page-header{ border-bottom :0px solid #000 !important; margin :0px !important; -} \ No newline at end of file +} + +.card-block { + text-align:center; + background-color:#ddd; +} + +.footer { + position: fixed; + bottom: 0; + left: 0; + height: auto; + background-color: #ef404a; + width: 100%; + } \ No newline at end of file diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index c2074720..82b99cf0 100644 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -14,11 +14,6 @@ <% end %> <% shop = Shop.first %> - - - - -