diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 234a1dc5..c3a3d3b9 100755 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -98,10 +98,10 @@ class Origami::CustomersController < BaseOrigamiController def update_sale_by_customer - id = params[:sale_id][0,3] - customer_id = params[:customer_id] - customer = Customer.find(customer_id) - + id = params[:sale_id][0,3] + customer_id = params[:customer_id] + customer = Customer.find(customer_id) + order_source = params[:type] # Check and find with card no # if(!customer_id.include? "CUS") # customer = Customer.find_by_paypar_account_no(customer_id) @@ -135,7 +135,7 @@ class Origami::CustomersController < BaseOrigamiController if status == true render json: JSON.generate({:status => true}) if(id == "SAL") - sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount) + sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount, nil, order_source) end else render json: JSON.generate({:status => false, :error_message => "Record not found"}) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 8e390015..6add4a12 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -20,10 +20,12 @@ class Origami::DiscountsController < BaseOrigamiController #discount page show from origami index with selected order def create + order_source = params[:cashier_type] sale_id = params[:sale_id] discount_items = JSON.parse(params[:discount_items]) overall_discount = params[:overall_discount] sub_total = params[:sub_total] + if Sale.exists?(sale_id) sale = Sale.find(sale_id) @@ -82,7 +84,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"OVERALLDISCOUNT" ) end - sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f) + sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f, nil,order_source) if !table.nil? result = {:status=> "Success", :table_id => table_id, :table_type => table.type } else @@ -102,6 +104,7 @@ class Origami::DiscountsController < BaseOrigamiController # Remove selected discount Items def remove_discount_items + order_source = params[:cashier_type] sale_id = params[:sale_id] discount_items = JSON.parse(params[:discount_items]) if Sale.exists?(sale_id) @@ -136,7 +139,7 @@ class Origami::DiscountsController < BaseOrigamiController # sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; # sale.save # Re-calc All Amount in Sale - sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount) + sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount, nil, order_source) if table.nil? result = {:status=> "Success"} else @@ -158,6 +161,7 @@ class Origami::DiscountsController < BaseOrigamiController # Remove all discount Items def remove_all_discount sale_id = params[:id] + order_source = params[:type] if Sale.exists?(sale_id) sale = Sale.find(sale_id) @@ -197,7 +201,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"REMOVEALLDISCOUNT" ) # Re-calc All Amount in Sale - sale.compute_by_sale_items(sale_id, sale.sale_items, 0) + sale.compute_by_sale_items(sale_id, sale.sale_items, 0, nil, order_source) if table.nil? result = {:status=> "Success"} else @@ -218,7 +222,7 @@ class Origami::DiscountsController < BaseOrigamiController # Member Discount def member_discount - + order_source = params[:cashier_type] sale_id = params[:sale_id] is_card = params[:is_card] sub_total = params[:sub_total] @@ -297,7 +301,7 @@ class Origami::DiscountsController < BaseOrigamiController if response["discount_bonus_earned"] discount_amount = discount_amount + response["discount_bonus_earned"] end - sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount') + sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount', order_source) result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type } elsif response["status"] == "500" result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type } diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index edee8a03..e5c0e741 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -443,7 +443,6 @@ class Origami::PaymentsController < BaseOrigamiController sale_payment = SalePayment.new sale_payment.process_payment(saleObj, current_user.name, cash, "foc" ,remark) - # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") # if bookings.count > 1 diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index 16239750..ef38d04f 100755 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -3,6 +3,7 @@ class Origami::SplitBillController < BaseOrigamiController def index dining_id = params[:dining_id] + @cashier_type = params[:type] @table = DiningFacility.find(dining_id) @booking = @table.get_booking @orders = Array.new @@ -76,6 +77,7 @@ class Origami::SplitBillController < BaseOrigamiController end def create + cashier_type = params[:cashier_type] order_ids = params[:order_ids] arr_order_ids = nil if !params[:arr_order_ids].nil? @@ -111,7 +113,7 @@ class Origami::SplitBillController < BaseOrigamiController if booking if booking.sale_id.nil? sale = Sale.new - status, sale_id = sale.generate_invoice_from_booking(params[:booking_id], current_user, current_user) + status, sale_id = sale.generate_invoice_from_booking(params[:booking_id], current_user, current_user, cashier_type) sale_data = Sale.find_by_sale_id(sale_id) else status = true @@ -324,7 +326,7 @@ class Origami::SplitBillController < BaseOrigamiController end sale = Sale.new - status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, current_user) + status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, current_user, cashier_type) end Promotion.promo_activate(sale) diff --git a/app/models/sale.rb b/app/models/sale.rb index 5e7042e5..c95617b2 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -343,7 +343,6 @@ class Sale < ApplicationRecord #compute - invoice total def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil) - sale = Sale.find(sale_id) sales_items = sale_itemss diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 91a4db1e..3ff4697e 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -208,8 +208,7 @@ class SalePayment < ApplicationRecord self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f self.payment_status = "paid" payment_method = self.save! - sale_update_payment_status(self.received_amount) - + sale_update_payment_status(self.received_amount) return payment_status end @@ -325,7 +324,7 @@ class SalePayment < ApplicationRecord sObj = Sale.find(self.sale_id) is_credit = 0 is_foc = 0 - is_cash = false + method_status = false sObj.sale_payments.each do |spay| all_received_amount += spay.payment_amount.to_f if spay.payment_method == "creditnote" @@ -334,12 +333,12 @@ class SalePayment < ApplicationRecord if spay.payment_method == "foc" is_foc = 1 end - if spay.payment_method.to_s == "cash" - is_cash = true + if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote" + method_status = true end end - if (self.sale.grand_total <= all_received_amount) && is_cash + if (self.sale.grand_total <= all_received_amount) && method_status if is_credit == 0 self.sale.payment_status = "paid" else @@ -386,7 +385,7 @@ class SalePayment < ApplicationRecord elsif paid_amount.to_f > 0 #|| paid_amount != "0.0" table_update_status(sObj) update_shift - elsif is_cash && paid_amount.to_f == 0 + elsif method_status && paid_amount.to_f == 0 table_update_status(sObj) update_shift end diff --git a/app/views/origami/discounts/index.html.erb b/app/views/origami/discounts/index.html.erb index ccb2c0e8..744ef62e 100755 --- a/app/views/origami/discounts/index.html.erb +++ b/app/views/origami/discounts/index.html.erb @@ -414,7 +414,7 @@ var cashier_type = "<%= @cashier_type %>"; var sub_total = $('#order-sub-total').text(); var ajax_url = "/origami/" + sale_id + "/discount"; - var params = { 'sale_id': sale_id, 'sub_total': sub_total, 'discount_items': discount_items, 'overall_discount': overall_discount }; + var params = { 'cashier_type' : cashier_type,'sale_id': sale_id, 'sub_total': sub_total, 'discount_items': discount_items, 'overall_discount': overall_discount }; $.ajax({ type: "POST", @@ -465,7 +465,7 @@ var cashier_type = "<%= @cashier_type %>"; } } - var params = { 'sale_id': sale_id, 'discount_items': JSON.stringify(discount_items) }; + var params = { 'cashier_type': cashier_type,'sale_id': sale_id, 'discount_items': JSON.stringify(discount_items) }; $.ajax({ type: "POST", url: "/origami/" + sale_id + "/remove_discount_items", @@ -496,7 +496,7 @@ var cashier_type = "<%= @cashier_type %>"; var sale_id = $('#sale-id').text(); $.ajax({ type: "GET", - url: "/origami/" + sale_id + "/remove_all_discount", + url: "/origami/" + sale_id + "/" + cashier_type + "/remove_all_discount", success: function(result){ swal({ title: "Information!", @@ -532,7 +532,7 @@ var cashier_type = "<%= @cashier_type %>"; // var params = {'sale_id':sale_id, 'sub_total':sub_total, 'account_types':account_types }; - var params = {'sale_id':sale_id, 'sub_total':sub_total }; + var params = {'cashier_type': cashier_type,'sale_id':sale_id, 'sub_total':sub_total }; $.ajax({ type: "POST", diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index eda3524a..47d5650f 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -809,7 +809,7 @@ //split bill process $('#split_bills').click(function(){ var dining_id = "<%= @dining.id %>"; - window.location.href = '/origami/table/' + dining_id + "/split_bills"; + window.location.href = '/origami/table/' + dining_id + "/" + cashier_type +"/split_bills"; }); $('#move').on('click', function () { diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 758a5273..867f6034 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -776,7 +776,7 @@ $('#request_bills').click(function() { //split bill process $('#split_bills').click(function(){ var dining_id = "<%= @room.id %>"; - window.location.href = '/origami/room/' + dining_id + "/split_bills"; + window.location.href = '/origami/room/' + dining_id + "/" + cashier_type + "/split_bills"; }); $('#move').on('click',function(){ diff --git a/app/views/origami/split_bill/index.html.erb b/app/views/origami/split_bill/index.html.erb index a62fb66e..95061960 100644 --- a/app/views/origami/split_bill/index.html.erb +++ b/app/views/origami/split_bill/index.html.erb @@ -333,6 +333,7 @@