From e2903075b2cba33dd9063279345d75c568475efc Mon Sep 17 00:00:00 2001 From: phyusin Date: Wed, 21 Feb 2018 18:24:04 +0630 Subject: [PATCH] change split bill equal person flow --- .../origami/payments_controller.rb | 22 ++--- .../origami/split_bill_controller.rb | 30 ++++--- app/controllers/origami/surveys_controller.rb | 80 ------------------- app/controllers/origami/void_controller.rb | 3 +- app/models/ability.rb | 1 + app/models/printer/receipt_printer.rb | 8 +- app/pdf/receipt_bill_a5_pdf.rb | 12 +-- app/pdf/receipt_bill_pdf.rb | 12 +-- app/views/origami/split_bill/index.html.erb | 29 ++----- config/routes.rb | 3 +- db/migrate/20170701101420_create_sales.rb | 1 + 11 files changed, 52 insertions(+), 149 deletions(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 33596e1e..e7786b05 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -8,7 +8,6 @@ class Origami::PaymentsController < BaseOrigamiController sale_data = Sale.find_by_sale_id(sale_id) sale_items = SaleItem.where("sale_id=?",sale_id) member_info = nil - survey = Survey.find_by_receipt_no(sale_data.receipt_no) # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") @@ -67,7 +66,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil,survey) + printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil) end end @@ -79,7 +78,6 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail - survey = Survey.find_by_receipt_no(saleObj.receipt_no) # rounding adjustment if shop_details.is_rounding_adj a = saleObj.grand_total % 25 # Modulus @@ -153,7 +151,7 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data,survey) + printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data) if params[:type] == "quick_service" booking = Booking.find_by_sale_id(sale_id) @@ -197,14 +195,10 @@ class Origami::PaymentsController < BaseOrigamiController 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 + if !saleObj.equal_persons.nil? + per_person_amount = saleObj.grand_total.to_f / saleObj.equal_persons.to_i + @individual_total.push({'total_customer' => saleObj.equal_persons.to_i, 'per_person_amount' => per_person_amount.to_f }) end # rounding adjustment @@ -295,7 +289,6 @@ class Origami::PaymentsController < BaseOrigamiController member_info = nil saleObj = Sale.find(sale_id) - survey = Survey.find_by_receipt_no(saleObj.receipt_no) # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") @@ -349,7 +342,7 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Re-print",current_balance,card_data,survey) + printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Re-print",current_balance,card_data) end end @@ -363,7 +356,6 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - survey = Survey.find_by_receipt_no(saleObj.receipt_no) if saleObj.discount_type == "member_discount" saleObj.update_attributes(rounding_adjustment: 0) @@ -408,7 +400,7 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC",nil,nil,survey) + printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC",nil,nil) end end end diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index e7265a7a..987f68e7 100644 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -146,15 +146,15 @@ class Origami::SplitBillController < BaseOrigamiController end end - puts order_id - puts order_ids.count - puts order_id_count - puts order_items.count - puts order_item_count + # puts order_id + # puts order_ids.count + # puts order_id_count + # puts order_items.count + # puts order_item_count if !order_id.nil? if order_id_count > 1 - puts "order_id_count > 1" + # puts "order_id_count > 1" updated_order_id = Array.new order_ids.each do |odr_id| @@ -164,8 +164,8 @@ class Origami::SplitBillController < BaseOrigamiController end end - puts "updated_order_id" - puts updated_order_id + # puts "updated_order_id" + # puts updated_order_id if !updated_order_id.empty? order_ids.each do |odr_id| @@ -194,7 +194,7 @@ class Origami::SplitBillController < BaseOrigamiController end end - puts new_order_status + # puts new_order_status if new_order_status BookingOrder.find_by_order_id(odr_id).delete @@ -222,7 +222,7 @@ class Origami::SplitBillController < BaseOrigamiController end end else - puts "order_id_count < 1" + # puts "order_id_count < 1" new_order_status = true order_items.each do |order_item| orderItem = OrderItem.find_by_order_id(order_id) @@ -235,7 +235,7 @@ class Origami::SplitBillController < BaseOrigamiController end end - puts new_order_status + # puts new_order_status if new_order_status BookingOrder.find_by_order_id(order_id).delete @@ -356,6 +356,14 @@ class Origami::SplitBillController < BaseOrigamiController orderItem.save! end + def update_sale + sale = Sale.find(params[:sale_id]) + sale.equal_persons = params[:total_customer].to_i + sale.save! + + render :json => { status: true } + end + #Shop Name in Navbor helper_method :shop_detail def shop_detail diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb index 12d6d543..47b7e8fd 100644 --- a/app/controllers/origami/surveys_controller.rb +++ b/app/controllers/origami/surveys_controller.rb @@ -84,86 +84,6 @@ class Origami::SurveysController < BaseOrigamiController end end - 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) - receipt_no = params[:receipt_no] - - if @type != "quick_service" - dining_facility = DiningFacility.find(params[:dining_id]) - cashier_zone = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id) - cashier_terminal_id = cashier_zone.cashier_terminal_id - else - shift = ShiftSale.find(sale.shift_sale_id) - cashier_terminal_id = shift.cashier_terminal_id - end - - 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_and_receipt_no(dining_facility.name,receipt_no) - else - survey = nil - end - - - if survey.nil? - if @type != "quick_service" - 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 - 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} - else - render :json => { status: false, error_message: 'No Current Open Shift!'} - 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/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index e4190cf7..4c9aa0c1 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -6,7 +6,6 @@ class Origami::VoidController < BaseOrigamiController if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) - survey = Survey.find_by_receipt_no(sale.receipt_no) if sale.discount_type == "member_discount" sale.update_attributes(total_discount: 0) @@ -125,7 +124,7 @@ class Origami::VoidController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,survey) + printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil) end #end print diff --git a/app/models/ability.rb b/app/models/ability.rb index f0091ef7..7afb6bc4 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -136,6 +136,7 @@ class Ability #ability for split_bill can :index, :split_bill can :create, :split_bill + can :update_sale, :split_bill elsif user.role == "account" diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index c60fcc35..0cf6526f 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -173,19 +173,19 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end #Bill Receipt Print - def print_receipt_bill(printer_settings,cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,survey) + def print_receipt_bill(printer_settings,cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data) #Use CUPS service #Generate PDF #Print - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,survey) + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' - pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,survey) + pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) else - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,survey) + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) end end end diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 0f7ea468..c4666963 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -1,7 +1,7 @@ class ReceiptBillA5Pdf < Prawn::Document include ActionView::Helpers::NumberHelper 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, :description_width, :price_num_width - def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,survey) + def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.margin = 15 @@ -80,8 +80,8 @@ class ReceiptBillA5Pdf < Prawn::Document end #start for individual payment - if !survey.nil? - individual_payment(sale_data, survey, printer_settings.precision, delimiter) + if !sale_data.equal_persons.nil? + individual_payment(sale_data, printer_settings.precision, delimiter) end #end for individual payment @@ -480,14 +480,14 @@ class ReceiptBillA5Pdf < Prawn::Document end #individual payment per person - def individual_payment(sale_data, survey, precision, delimiter) - per_person = sale_data.grand_total.to_f / survey.total_customer.to_i + def individual_payment(sale_data, precision, delimiter) + per_person = sale_data.grand_total.to_f / sale_data.equal_persons.to_i move_down 5 stroke_horizontal_rule move_down 5 y_position = cursor bounding_box([0,y_position], :width =>self.label_width+50) do - text "Individual amount for #{survey.total_customer} persons", :size => self.item_font_size+1,:align => :left + text "Individual amount for #{sale_data.equal_persons} persons", :size => self.item_font_size+1,:align => :left end bounding_box([0,y_position], :width =>self.label_width) do diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 31317c0e..aef26a9d 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,7 +1,7 @@ class ReceiptBillPdf < Prawn::Document include ActionView::Helpers::NumberHelper 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, :description_width, :price_num_width - def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,survey) + def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data) self.page_width = printer_settings.page_width self.page_height = printer_settings.page_height self.margin = 0 @@ -80,8 +80,8 @@ class ReceiptBillPdf < Prawn::Document end #start for individual payment - if !survey.nil? - individual_payment(sale_data, survey, printer_settings.precision, delimiter) + if !sale_data.equal_persons.nil? + individual_payment(sale_data, printer_settings.precision, delimiter) end #end for individual payment @@ -481,14 +481,14 @@ class ReceiptBillPdf < Prawn::Document end #individual payment per person - def individual_payment(sale_data, survey, precision, delimiter) - per_person = sale_data.grand_total.to_f / survey.total_customer.to_i + def individual_payment(sale_data, precision, delimiter) + per_person = sale_data.grand_total.to_f / sale_data.equal_persons.to_i move_down 5 stroke_horizontal_rule move_down 5 y_position = cursor bounding_box([0,y_position], :width =>self.label_width+50) do - text "Individual amount for #{survey.total_customer} persons", :size => self.item_font_size+1,:align => :left + text "Individual amount for #{sale_data.equal_persons} persons", :size => self.item_font_size+1,:align => :left end bounding_box([0,y_position], :width =>self.label_width) do diff --git a/app/views/origami/split_bill/index.html.erb b/app/views/origami/split_bill/index.html.erb index 72f08c83..5750bc2f 100755 --- a/app/views/origami/split_bill/index.html.erb +++ b/app/views/origami/split_bill/index.html.erb @@ -318,7 +318,6 @@