split bill process

This commit is contained in:
phyusin
2018-02-20 13:33:59 +06:30
parent 8ccf45d06f
commit 4bfb5842bf
7 changed files with 88 additions and 18 deletions

View File

@@ -186,9 +186,21 @@ class Origami::PaymentsController < BaseOrigamiController
@table_no = '' @table_no = ''
@dining = '' @dining = ''
@shop = Shop::ShopDetail @shop = Shop::ShopDetail #show shop info
saleObj = Sale.find(sale_id) 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 # rounding adjustment
if @shop.is_rounding_adj if @shop.is_rounding_adj
a = saleObj.grand_total % 25 # Modulus a = saleObj.grand_total % 25 # Modulus

View File

@@ -86,9 +86,10 @@ class Origami::SurveysController < BaseOrigamiController
def create_survey def create_survey
if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id) if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id)
@type = params[:cashier_type] @type = params[:cashier_type]
@sale_id = params[:sale_id] @sale_id = params[:sale_id]
sale = Sale.find(@sale_id) sale = Sale.find(@sale_id)
receipt_no = params[:receipt_no]
if @type != "quick_service" if @type != "quick_service"
dining_facility = DiningFacility.find(params[:dining_id]) 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) shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_terminal_id,nil)
if @type != "quick_service" 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 else
survey = nil survey = nil
end end
if survey.nil? if survey.nil?
survey = Survey.new
if @type != "quick_service" 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 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 else
survey.receipt_no = params[:receipt_no] survey.receipt_no = params[:receipt_no]
survey.total_customer = params[:total_customer] survey.total_customer = params[:total_customer]
survey.total_amount = params[:total_amount]
survey.save! survey.save!
end end
render :json => {status: true} render :json => {status: true}
@@ -131,6 +148,22 @@ class Origami::SurveysController < BaseOrigamiController
end end
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 private
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.

View File

@@ -484,7 +484,7 @@ class ReceiptBillA5Pdf < Prawn::Document
bounding_box([0,y_position], :width =>self.label_width) do bounding_box([0,y_position], :width =>self.label_width) do
move_down 15 move_down 15
text "Total", :size => self.item_font_size,:align => :left text "Total Amount", :size => self.item_font_size,:align => :left
end end
bounding_box([self.label_width,y_position], :width =>self.item_description_width) do bounding_box([self.label_width,y_position], :width =>self.item_description_width) do

View File

@@ -493,7 +493,7 @@ class ReceiptBillPdf < Prawn::Document
bounding_box([0,y_position], :width =>self.label_width) do bounding_box([0,y_position], :width =>self.label_width) do
move_down 15 move_down 15
text "Total", :size => self.item_font_size,:align => :left text "Total Amount", :size => self.item_font_size,:align => :left
end end
bounding_box([self.label_width,y_position], :width =>self.item_description_width) do bounding_box([self.label_width,y_position], :width =>self.item_description_width) do

View File

@@ -107,6 +107,14 @@
<td class="item-attr"><strong><span><%=@balance%></span></strong></td> <td class="item-attr"><strong><span><%=@balance%></span></strong></td>
</tr> </tr>
<% end %> <% end %>
<% if !@individual_total.nil? %>
<tr>
<td class="charges-name">
<strong>Individual amount for <%= @individual_total[0]['total_customer'] %> persons</strong>
</td>
<td class="item-attr"><strong><span><%=@individual_total[0]['per_person_amount']%></span></strong></td>
</tr>
<% end %>
</tfooter> </tfooter>
</table> </table>
</div> </div>

View File

@@ -318,7 +318,6 @@
var split_receipt_no = ""; var split_receipt_no = "";
var split_total_amount = 0; var split_total_amount = 0;
$(document).ready(function(){ $(document).ready(function(){
$('#back').on('click',function(){ $('#back').on('click',function(){
backToOrigami(); backToOrigami();
}) })
@@ -472,9 +471,26 @@
//equal split process //equal split process
$('#equal_split').on('click', function(){ $('#equal_split').on('click', function(){
var dining_id = $("#table_id").text();
split_sale_id = $("input[type='radio'][name='rdn_receipt']:checked").val(); 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_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'); 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 != ""){ if(split_sale_id != undefined && split_sale_id != ""){
$('#equal_split_modal').modal({backdrop: 'static', keyboard: true, show: true}); $('#equal_split_modal').modal({backdrop: 'static', keyboard: true, show: true});
} }

View File

@@ -239,6 +239,7 @@ scope "(:locale)", locale: /en|mm/ do
post '/split_bills', to: 'split_bill#create', as:"order_item_split_bills" post '/split_bills', to: 'split_bill#create', as:"order_item_split_bills"
post '/split_bills/surveys', to: 'surveys#create_survey' post '/split_bills/surveys', to: 'surveys#create_survey'
post '/split_bills/get_survey', to: 'surveys#get_survey'
end end