check order item split process

This commit is contained in:
phyusin
2018-02-16 15:11:16 +06:30
parent 0ddaee7444
commit d459a6e2a3
8 changed files with 199 additions and 81 deletions

View File

@@ -15,6 +15,13 @@ class Origami::OrdersController < BaseOrigamiController
@booking.push({'booking_id' => booking.booking_id, 'dining_facility_id' => booking.dining_facility_id, 'type' => dining_facilities.type})
end
#for split bill
lookup_spit_bill = Lookup.collection_of('split_bill')
@split_bill = 0
if !lookup_spit_bill[0].nil?
@split_bill = lookup_spit_bill[0][1]
end
sale_order = SaleOrder.find_by_order_id(@order.order_id)
if sale_order
unless sale_order.sale_id.nil?

View File

@@ -149,6 +149,8 @@ class Origami::SplitBillController < BaseOrigamiController
if !order_id.nil?
if order_id_count > 1
puts "order_id_count > 1"
updated_order_id = Array.new
order_ids.each do |odr_id|
odr = Order.find(odr_id)
@@ -157,10 +159,13 @@ class Origami::SplitBillController < BaseOrigamiController
end
end
puts "updated_order_id"
puts updated_order_id
if !updated_order_id.empty?
order_ids.each do |odr_id|
unless updated_order_id.include?(odr_id)
# BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
end
end
@@ -172,16 +177,102 @@ class Origami::SplitBillController < BaseOrigamiController
end
else
order_ids.each do |odr_id|
# BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
new_order_status = true
order_items.each do |order_item|
orderItem = OrderItem.find_by_order_id(odr_id)
if !orderItem.nil?
if order_item["id"] == orderItem.order_items_id
if orderItem.qty.to_f != order_item['qty'].to_f
new_order_status = false
end
end
end
end
if new_order_status
BookingOrder.find_by_order_id(odr_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = Order.new
order.source = "cashier"
order.order_type = order_type
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
order.item_count = order_items.count
order.status = "new"
order.table_id = params[:dining_id] # this is dining facilities's id
order.waiters = current_user.name
order.employee_name = current_user.name
order.guest_info = nil
order.save!
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
end
end
end
else
BookingOrder.find_by_order_id(order_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id})
puts "order_id_count < 1"
new_order_status = true
order_items.each do |order_item|
update_order_item(order_id, order_item)
orderItem = OrderItem.find_by_order_id(order_id)
if !orderItem.nil?
if order_item["id"] == orderItem.order_items_id
if orderItem.qty.to_f != order_item['qty'].to_f
new_order_status = false
end
end
end
end
if new_order_status
BookingOrder.find_by_order_id(order_id).delete
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id})
order_items.each do |order_item|
update_order_item(order_id, order_item)
end
else
customer = Customer.find(params[:customer_id])
order_type = "dine_in"
if !customer.nil?
if customer.customer_type == "Takeaway"
order_type = "takeaway"
elsif customer.customer_type == "Delivery"
order_type = "delivery"
end
end
# begin
order = Order.new
order.source = "cashier"
order.order_type = order_type
order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile
order.item_count = order_items.count
order.status = "new"
order.table_id = params[:dining_id] # this is dining facilities's id
order.waiters = current_user.name
order.employee_name = current_user.name
order.guest_info = nil
order.save!
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.order_id, order_item)
end
end
end
else
@@ -217,7 +308,7 @@ class Origami::SplitBillController < BaseOrigamiController
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item|
update_order_item(order.id, order_item)
update_order_item(order.order_id, order_item)
end
end
end

View File

@@ -478,11 +478,17 @@ class ReceiptBillA5Pdf < Prawn::Document
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
end
bounding_box([0,y_position], :width =>self.label_width) do
text "Individual amount", :size => self.item_font_size,:align => :left
move_down 15
text "Total", :size => self.item_font_size,:align => :left
end
bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
move_down 15
text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)} per person", :size => self.item_font_size,:align => :right
end
end

View File

@@ -478,11 +478,17 @@ class ReceiptBillPdf < Prawn::Document
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
end
bounding_box([0,y_position], :width =>self.label_width) do
text "Individual amount", :size => self.item_font_size,:align => :left
move_down 15
text "Total", :size => self.item_font_size,:align => :left
end
bounding_box([self.label_width,y_position], :width =>self.item_description_width) do
move_down 15
text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)} per person", :size => self.item_font_size,:align => :right
end
end

View File

@@ -387,14 +387,7 @@
%>
</table>
<% if !@split_bill.nil? %>
<% if @split_bill == '1' %>
<button class='btn btn-primary waves-effect' id='add_invoice'> Add to existing invoice</button>
<button class='btn btn-primary waves-effect' id='split_bill'> Split Bill</button>
<% else %>
<button class='btn btn-primary btn-block waves-effect' id='add_invoice'> Add to existing invoice</button>
<% end %>
<% end %>
<button class='btn btn-primary btn-block waves-effect' id='add_invoice'> Add to existing invoice</button>
<% end %>
<% if @sale_array.size > 1 %>
<br><br>
@@ -412,11 +405,6 @@
<button class='btn btn-sm btn-primary invoicedetails' id="<%= sale.sale_id %>">Show
Detail
</button>
<% if !@split_bill.nil? %>
<% if @split_bill == '1' %>
<button class='btn btn-sm btn-primary waves-effect' id='split_bill'> Split Bill</button>
<% end %>
<% end %>
</td>
</tr>
</table>
@@ -476,6 +464,11 @@
<button type="button" id="first_bill" class="btn btn-block bg-blue waves-effect">First Bill</button>
<%end%>
<% end %>
<% if !@split_bill.nil? %>
<% if @split_bill == '1' %>
<button type="button" id="split_bills" class="btn btn-block bg-blue waves-effect">Split Bill</button>
<% end %>
<% end %>
<button type="button" id="pay" class="btn btn-block bg-blue waves-effect">Pay</button>
<% end %>

View File

@@ -241,7 +241,9 @@
<!-- Column Three -->
<div class="col-lg-1 col-md-1 col-sm-1">
<button type="button" class="btn bg-default btn-block waves-effect" id='back'><i class="material-icons">reply</i>Back</button>
<% if !@split_bill.nil? && @split_bill == '1' %>
<button type="button" class="btn bg-blue btn-block waves-effect" id='by_order'>By Order</button>
<% end %>
<% if @sale_status != 'completed' %>
<!-- <button type="button" class="btn bg-blue btn-block" id='move'>MOVE</button> -->
<% end %>
@@ -312,7 +314,7 @@
var order = JSON.parse('<%= @order.to_json.html_safe %>');
var arr_order = [];
arr_order.push({id : order.order_id});
var dining_id = booking[0].dining_facility_id || 0;
var type = booking[0].type || '';
var customer_id = order.customer_id || '';

View File

@@ -364,10 +364,7 @@
end
%>
</table>
<button class='btn bg-primary' id='add_invoice'> Add to existing invoice </button>
<% if !@split_bill.nil? && @split_bill == '1' %>
<button class='btn btn-primary' id='split_bill'> Split Bill</button>
<% end %>
<button class='btn bg-primary btn-block' id='add_invoice'> Add to existing invoice </button>
<% end %>
<% if @sale_array.size > 1 %>
<br><br>
@@ -440,6 +437,11 @@
<button type="button" id="first_bill" class="btn btn-block bg-blue waves-effect">First Bill</button>
<%end%>
<%end%>
<% if !@split_bill.nil? %>
<% if @split_bill == '1' %>
<button type="button" id="split_bills" class="btn btn-block bg-blue waves-effect">Split Bill</button>
<% end %>
<% end %>
<button type="button" id="pay" class="btn bg-blue btn-block">Pay</button>
<!-- <button type="button" id="void" class="btn bg-blue btn-block" > Void </button> -->
<% end %>

View File

@@ -200,7 +200,7 @@
<% @sale_data.each_with_index do |sale_data, sale_index| %>
<% if sale_data.sale_status != 'completed' && sale_data.sale_status != 'void' %>
<% checked = "" %>
<% if sale_index == 0 %>
<% if sale_index == 1 %>
<% checked = "checked" %>
<% end %>
<tr class="receipt-row" id=<%= sale_data.receipt_no %> data=<%= sale_data.grand_total %> >
@@ -250,7 +250,8 @@
<div class="form-horizontal">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="form-group">
<input type="text" id="per_person" name="per_person" class="form-control" onkeypress="return isNumberKey(event);"/>
<input type="text" id="per_person" name="per_person" class="form-control" onkeypress="return isNumberKey(event);"/><br>
<span id="per_personErr" style="color:red;"></span>
</div>
</div>
</div>
@@ -304,7 +305,7 @@
</div>
<div class="modal-footer">
<button type="button" class="btn bg-default" data-dismiss="modal">Close</button> &nbsp;&nbsp;
<button type="button" class="btn bg-blue btn_per_person">Split Bill</button>
<button type="button" class="btn bg-blue btn_per_person">= Split</button>
</div>
</div>
</div>
@@ -483,58 +484,68 @@
});
$('.btn_per_person').on('click', function(){
$('#equal_split_modal').modal('hide');
var person = parseInt($('#per_person').val());
if(person > 1){
var ajax_url = "/origami/split_bills/surveys";
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 },
success: function (result) {
console.log(result);
if(result.status){
var ajax_url = "/origami/sale/" + split_sale_id + "/first_bill";
$.ajax({
type: "GET",
url: ajax_url,
success: function (result) {
if((split_receipt_no!=undefined) && (split_receipt_no!=""))
createReceiptNoInFirstBillData(split_receipt_no,"");
location.reload();
// if(type=='Table'){
// window.location.href = '/origami/table/' + dining_id;
// }else{
// window.location.href = '/origami/room/' + dining_id;
// }
}
});
}
}
});
var person = $('#per_person').val();
if((person!=undefined) && (person!="")){
$("#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 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 },
success: function (result) {
console.log(result);
if(result.status){
var ajax_url = "/origami/sale/" + split_sale_id + "/first_bill";
$.ajax({
type: "GET",
url: ajax_url,
success: function (result) {
if((split_receipt_no!=undefined) && (split_receipt_no!=""))
createReceiptNoInFirstBillData(split_receipt_no,"");
// location.reload();
// if(type=='Table'){
// window.location.href = '/origami/table/' + dining_id;
// }else{
// window.location.href = '/origami/room/' + dining_id;
// }
window.location.href = '/origami/sale/' + split_sale_id + "/payment";
}
});
}
}
});
}else{
var ajax_url = "/origami/sale/" + split_sale_id + "/first_bill";
$.ajax({
type: "GET",
url: ajax_url,
success: function (result) {
if((split_receipt_no!=undefined) && (split_receipt_no!=""))
createReceiptNoInFirstBillData(split_receipt_no,"");
// location.reload();
// if(type=='Table'){
// window.location.href = '/origami/table/' + dining_id;
// }else{
// window.location.href = '/origami/room/' + dining_id;
// }
window.location.href = '/origami/sale/' + split_sale_id + "/payment";
}
});
}
}else{
var ajax_url = "/origami/sale/" + split_sale_id + "/first_bill";
$.ajax({
type: "GET",
url: ajax_url,
success: function (result) {
if((split_receipt_no!=undefined) && (split_receipt_no!=""))
createReceiptNoInFirstBillData(split_receipt_no,"");
location.reload();
// if(type=='Table'){
// window.location.href = '/origami/table/' + dining_id;
// }else{
// window.location.href = '/origami/room/' + dining_id;
// }
}
});
$("#per_personErr").html("can't be blank");
}
});
//equal split process