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}) @booking.push({'booking_id' => booking.booking_id, 'dining_facility_id' => booking.dining_facility_id, 'type' => dining_facilities.type})
end 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) sale_order = SaleOrder.find_by_order_id(@order.order_id)
if sale_order if sale_order
unless sale_order.sale_id.nil? unless sale_order.sale_id.nil?

View File

@@ -149,6 +149,8 @@ class Origami::SplitBillController < BaseOrigamiController
if !order_id.nil? if !order_id.nil?
if order_id_count > 1 if order_id_count > 1
puts "order_id_count > 1"
updated_order_id = Array.new updated_order_id = Array.new
order_ids.each do |odr_id| order_ids.each do |odr_id|
odr = Order.find(odr_id) odr = Order.find(odr_id)
@@ -157,10 +159,13 @@ class Origami::SplitBillController < BaseOrigamiController
end end
end end
puts "updated_order_id"
puts updated_order_id
if !updated_order_id.empty? if !updated_order_id.empty?
order_ids.each do |odr_id| order_ids.each do |odr_id|
unless updated_order_id.include?(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}) BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id})
end end
end end
@@ -172,16 +177,102 @@ class Origami::SplitBillController < BaseOrigamiController
end end
else else
order_ids.each do |odr_id| order_ids.each do |odr_id|
# BookingOrder.find_by_order_id(odr_id).delete new_order_status = true
BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id}) 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
end end
else else
BookingOrder.find_by_order_id(order_id).delete puts "order_id_count < 1"
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id}) new_order_status = true
order_items.each do |order_item| 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
end end
else else
@@ -217,7 +308,7 @@ class Origami::SplitBillController < BaseOrigamiController
BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id}) BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id})
order_items.each do |order_item| order_items.each do |order_item|
update_order_item(order.id, order_item) update_order_item(order.order_id, order_item)
end end
end end
end end

View File

@@ -478,11 +478,17 @@ class ReceiptBillA5Pdf < Prawn::Document
stroke_horizontal_rule stroke_horizontal_rule
move_down 5 move_down 5
y_position = cursor 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 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 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
move_down 15
text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)} per person", :size => self.item_font_size,:align => :right text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)} per person", :size => self.item_font_size,:align => :right
end end
end end

View File

@@ -478,11 +478,17 @@ class ReceiptBillPdf < Prawn::Document
stroke_horizontal_rule stroke_horizontal_rule
move_down 5 move_down 5
y_position = cursor 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 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 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
move_down 15
text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)} per person", :size => self.item_font_size,:align => :right text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)} per person", :size => self.item_font_size,:align => :right
end end
end end

View File

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

View File

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

View File

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

View File

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