From 4bfb5842bfb09c4727609a06056d76e3ac893d5e Mon Sep 17 00:00:00 2001 From: phyusin Date: Tue, 20 Feb 2018 13:33:59 +0630 Subject: [PATCH 1/6] split bill process --- .../origami/payments_controller.rb | 14 ++++- app/controllers/origami/surveys_controller.rb | 59 +++++++++++++++---- app/pdf/receipt_bill_a5_pdf.rb | 2 +- app/pdf/receipt_bill_pdf.rb | 2 +- app/views/origami/payments/show.html.erb | 8 +++ app/views/origami/split_bill/index.html.erb | 20 ++++++- config/routes.rb | 1 + 7 files changed, 88 insertions(+), 18 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 82761dd1..28a82d83 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -186,9 +186,21 @@ class Origami::PaymentsController < BaseOrigamiController @table_no = '' @dining = '' - @shop = Shop::ShopDetail + @shop = Shop::ShopDetail #show shop info saleObj = Sale.find(sale_id) + + #total customer with individual total amount + survey = nil + @individual_total = Array.new + if !@sale_data.nil? + survey = Survey.find_by_receipt_no(@sale_data.receipt_no) + if !survey.nil? + per_person_amount = saleObj.grand_total.to_f / survey.total_customer.to_i + @individual_total.push({'total_customer' => survey.total_customer, 'per_person_amount' => per_person_amount.to_f }) + end + end + # rounding adjustment if @shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb index 02ec9795..12d6d543 100644 --- a/app/controllers/origami/surveys_controller.rb +++ b/app/controllers/origami/surveys_controller.rb @@ -86,9 +86,10 @@ class Origami::SurveysController < BaseOrigamiController def create_survey if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id) - @type = params[:cashier_type] - @sale_id = params[:sale_id] - sale = Sale.find(@sale_id) + @type = params[:cashier_type] + @sale_id = params[:sale_id] + sale = Sale.find(@sale_id) + receipt_no = params[:receipt_no] if @type != "quick_service" dining_facility = DiningFacility.find(params[:dining_id]) @@ -102,27 +103,43 @@ class Origami::SurveysController < BaseOrigamiController shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_terminal_id,nil) if @type != "quick_service" - survey = Survey.find_by_dining_name(dining_facility.name) + survey = Survey.find_by_dining_name_and_receipt_no(dining_facility.name,receipt_no) else survey = nil end if survey.nil? - survey = Survey.new if @type != "quick_service" - survey.dining_name = dining_facility.name + survey = Survey.find_by_dining_name_and_receipt_no(dining_facility.name,nil) + if survey.nil? + survey = Survey.new + survey.dining_name = dining_facility.name + survey.receipt_no = params[:receipt_no] + survey.shift_id = shift_by_terminal.id + survey.created_by = current_user.name + survey.total_customer = params[:total_customer] + survey.total_amount = params[:total_amount] + survey.save! + else + survey.receipt_no = params[:receipt_no] + survey.total_customer = params[:total_customer] + survey.total_amount = params[:total_amount] + survey.save! + end + else + survey = Survey.new + survey.receipt_no = params[:receipt_no] + survey.shift_id = shift_by_terminal.id + survey.created_by = current_user.name + survey.total_customer = params[:total_customer] + survey.total_amount = params[:total_amount] + survey.save! end - - survey.receipt_no = params[:receipt_no] - survey.shift_id = shift_by_terminal.id - survey.created_by = current_user.name - survey.total_customer = params[:total_customer] - survey.total_amount = params[:total_amount] - survey.save! else survey.receipt_no = params[:receipt_no] survey.total_customer = params[:total_customer] + survey.total_amount = params[:total_amount] survey.save! end render :json => {status: true} @@ -131,6 +148,22 @@ class Origami::SurveysController < BaseOrigamiController end end + def get_survey + dining_id = params[:dining_id] + receipt_no = params[:receipt_no] + table = DiningFacility.find_by_id(dining_id) + survey = Survey.find_by_dining_name_and_receipt_no(table.name,receipt_no) + if survey.nil? + survey = Survey.find_by_dining_name_and_receipt_no(table.name,nil) + end + + if !survey.nil? + render :json => { status: true, survey: survey } + else + render :json => { status: false } + end + end + private # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 6125078b..5655cc38 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -484,7 +484,7 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([0,y_position], :width =>self.label_width) do move_down 15 - text "Total", :size => self.item_font_size,:align => :left + text "Total Amount", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 2f7fa0eb..64348fe8 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -493,7 +493,7 @@ class ReceiptBillPdf < Prawn::Document bounding_box([0,y_position], :width =>self.label_width) do move_down 15 - text "Total", :size => self.item_font_size,:align => :left + text "Total Amount", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 8c275785..9cb9f397 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -107,6 +107,14 @@ <%=@balance%> <% end %> + <% if !@individual_total.nil? %> + + + Individual amount for <%= @individual_total[0]['total_customer'] %> persons + + <%=@individual_total[0]['per_person_amount']%> + + <% end %> diff --git a/app/views/origami/split_bill/index.html.erb b/app/views/origami/split_bill/index.html.erb index f246e98c..a423f298 100755 --- a/app/views/origami/split_bill/index.html.erb +++ b/app/views/origami/split_bill/index.html.erb @@ -249,7 +249,7 @@