change split bill equal person flow

This commit is contained in:
phyusin
2018-02-21 18:24:04 +06:30
parent d991a9f0ee
commit e2903075b2
11 changed files with 52 additions and 149 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -318,7 +318,6 @@
<script type="text/javascript">
var split_sale_id = "";
var split_receipt_no = "";
var split_total_amount = 0;
$(document).ready(function(){
$('#back').on('click',function(){
backToOrigami();
@@ -396,7 +395,7 @@
// orderItemSplitBillProcess(cnt_items);
// }
}else{
swal("Opps","Please select at least one item!","warning");
swal("Oops","Please select at least one item!","warning");
}
});
@@ -460,7 +459,7 @@
// orderSplitBillProcess(cnt_odrs);
// }
}else{
swal("Opps","Please select at least one order!","warning");
swal("Oops","Please select at least one order!","warning");
}
});
@@ -476,28 +475,12 @@
var dining_id = $("#table_id").text();
split_sale_id = $("input[type='radio'][name='rdn_receipt']:checked").val();
split_receipt_no = $("input[type='radio'][name='rdn_receipt']:checked").parent().parent().attr('id');
split_total_amount = $("input[type='radio'][name='rdn_receipt']:checked").parent().parent().attr('data');
$.ajax({
type: "POST",
url: "/origami/split_bills/get_survey",
dataType: 'JSON',
data: {'dining_id':dining_id, 'receipt_no':split_receipt_no },
success: function (result) {
if(result.status){
if(parseInt(result.survey.total_customer) > 0){
$("#per_person").val(parseInt(result.survey.total_customer));
}else{
$("#per_person").val("");
}
}
}
});
if(split_sale_id != undefined && split_sale_id != ""){
$('#equal_split_modal').modal({backdrop: 'static', keyboard: true, show: true});
}
else{
swal("Opps","Please select one receipt!","warning");
swal("Oops","Please select one receipt!","warning");
}
});
@@ -508,15 +491,15 @@
$("#per_personErr").html('');
$('#equal_split_modal').modal('hide');
if(person > 1){
var ajax_url = "/origami/split_bills/surveys";
var dining_id = $("#table_id").text();
var ajax_url = "/origami/split_bills/equal_person";
var dining_id = $("#table_id").text();
var type = $("#table_type").text();
$.ajax({
type: "POST",
url: ajax_url,
dataType: 'JSON',
data: {'dining_id':dining_id, 'sale_id':split_sale_id, 'receipt_no':split_receipt_no, 'total_customer': person, 'total_amount':split_total_amount },
data: { 'sale_id':split_sale_id, 'total_customer': person },
success: function (result) {
console.log(result);
if(result.status){

View File

@@ -238,8 +238,7 @@ scope "(:locale)", locale: /en|mm/ do
get '/room/:dining_id/split_bills' => 'split_bill#index'
post '/split_bills', to: 'split_bill#create', as:"order_item_split_bills"
post '/split_bills/surveys', to: 'surveys#create_survey'
post '/split_bills/get_survey', to: 'surveys#get_survey'
post '/split_bills/equal_person', to: 'split_bill#update_sale'
end

View File

@@ -24,6 +24,7 @@ class CreateSales < ActiveRecord::Migration[5.1]
t.integer :shift_sale_id
t.decimal :old_grand_total
t.string :rebate_status
t.integer :equal_persons
t.timestamps
end
end