diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 855ee984..7ce4e1ed 100755 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -462,4 +462,9 @@ iframe { /* section class for webview */ .section-margin { margin-top: -50px; +} + +.tax-btn-box { + width: 230px; + height: 80px; } \ No newline at end of file diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 40d8c573..313cc10c 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -96,6 +96,8 @@ class Origami::PaymentsController < BaseOrigamiController cash = params[:cash] sale_id = params[:sale_id] member_info = nil + type = params[:type] + tax_type = params[:tax_type] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) @@ -298,11 +300,18 @@ class Origami::PaymentsController < BaseOrigamiController # accounts = @customer.tax_profiles accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC") @account_arr =[] + @tax_arr =[] accounts.each do |acc| account = TaxProfile.find(acc.id) - @account_arr.push(account.name) + # @account_arr.push(account) + @tax_arr.push(account.name) + end + sale_taxes = SaleTax.where("sale_id = ?", saleObj.sale_id) + if !sale_taxes.empty? + sale_taxes.each do |sale_tax| + @account_arr.push(sale_tax) + end end - rebate = MembershipSetting.find_by_rebate(1) # get member information if @customer.membership_id != nil && rebate @@ -571,4 +580,15 @@ class Origami::PaymentsController < BaseOrigamiController render :json => result.to_json # render :json => {status: true} end + + #changable tax for sale + def change_tax + sale_id = params[:sale_id] + order_source = params[:cashier_type] + tax_type = params[:tax_type] + sale = Sale.find(sale_id) + sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount,nil,order_source,tax_type) + + render json: JSON.generate({:status => true}) + end end \ No newline at end of file diff --git a/app/models/ability.rb b/app/models/ability.rb index fbf66f57..9f1f105b 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -71,6 +71,7 @@ class Ability can :rounding_adj, :payment can :foc, :payment can :print, :payment + can :change_tax, :payment can :move_dining, :movetable can :moving, :movetable @@ -154,6 +155,7 @@ class Ability can :rounding_adj, :payment can :foc, :payment can :print, :payment + can :change_tax, :payment can :move_dining, :movetable can :moving, :movetable @@ -249,6 +251,7 @@ class Ability can :rounding_adj, :payment can :print, :payment can :foc, :payment + can :change_tax, :payment can :manage, Commission can :manage, Commissioner diff --git a/app/models/order.rb b/app/models/order.rb index 9a52942e..fea98438 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -317,10 +317,10 @@ class Order < ApplicationRecord #Send to background job for processing # OrderBroadcastJob.perform_later(table,type) if ENV["SERVER_MODE"] == 'cloud' - from = request.subdomain + "." + request.domain - else - from = "" - end + from = request.subdomain + "." + request.domain + else + from = "" + end ActionCable.server.broadcast "order_channel",table: table,type:type,from:from end diff --git a/app/models/sale.rb b/app/models/sale.rb index 24d3f81c..b7547c23 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -131,7 +131,6 @@ class Sale < ApplicationRecord if order_source.nil? order_source = order.source end - puts "compute source" compute(order_source) #Update the order items that is billed @@ -346,7 +345,7 @@ class Sale < ApplicationRecord end #compute - invoice total - def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil) + def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil,tax_type=nil) sale = Sale.find(sale_id) sales_items = sale_itemss @@ -365,7 +364,7 @@ class Sale < ApplicationRecord end end - compute_tax(sale, total_taxable, total_discount, order_source) + compute_tax(sale, total_taxable, total_discount, order_source, tax_type) sale.total_amount = subtotal_price sale.total_discount = total_discount @@ -412,7 +411,7 @@ class Sale < ApplicationRecord end # Tax Re-Calculte - def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil) + def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil, tax_type=nil) shop = Shop.first(); #if tax is not apply create new record @@ -429,60 +428,59 @@ class Sale < ApplicationRecord if sale.payment_status != 'foc' tax_profiles.each do |tax| - # customer.tax_profiles.each do |cus_tax| - # if cus_tax.to_i == tax.id if tax.group_type.to_s == order_source.to_s - if customer.customer_type.downcase == 'takeaway' - if tax.name.downcase == 'commercial tax' - sale_tax = SaleTax.new(:sale => sale) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate + if tax_type + if tax_type.to_s == tax.name.to_s || tax_type == 'all' + sale_tax = SaleTax.new(:sale => sale) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate - # substract , to give after discount - total_tax = total_taxable - total_discount - #include or execulive - if tax.inclusive - rate = tax.rate - divided_value = (100 + rate)/rate - sale_tax.tax_payable_amount = total_tax / divided_value - else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 - total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount + # substract , to give after discount + total_tax = total_taxable - total_discount + #include or execulive + if tax.inclusive + rate = tax.rate + divided_value = (100 + rate)/rate + sale_tax.tax_payable_amount = total_tax / divided_value + else + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount + end + #new taxable amount is standard rule for step by step + if shop.calc_tax_order + total_taxable = total_taxable + sale_tax.tax_payable_amount + end + sale_tax.inclusive = tax.inclusive + sale_tax.save end - #new taxable amount is standard rule for step by step - if shop.calc_tax_order - total_taxable = total_taxable + sale_tax.tax_payable_amount - end - - sale_tax.inclusive = tax.inclusive - sale_tax.save - end else - sale_tax = SaleTax.new(:sale => sale) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate + # customer.tax_profiles.each do |cus_tax| + # if cus_tax.to_i == tax.id + sale_tax = SaleTax.new(:sale => sale) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate - # substract , to give after discount - total_tax = total_taxable - total_discount - #include or execulive - if tax.inclusive - rate = tax.rate - divided_value = (100 + rate)/rate - sale_tax.tax_payable_amount = total_tax / divided_value - else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 - total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount - end - #new taxable amount is standard rule for step by step - if shop.calc_tax_order - total_taxable = total_taxable + sale_tax.tax_payable_amount - end - sale_tax.inclusive = tax.inclusive - sale_tax.save + # substract , to give after discount + total_tax = total_taxable - total_discount + #include or execulive + if tax.inclusive + rate = tax.rate + divided_value = (100 + rate)/rate + sale_tax.tax_payable_amount = total_tax / divided_value + else + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount + end + #new taxable amount is standard rule for step by step + if shop.calc_tax_order + total_taxable = total_taxable + sale_tax.tax_payable_amount + end + sale_tax.inclusive = tax.inclusive + sale_tax.save + # end + # end end end - # end - # end end end @@ -510,11 +508,9 @@ class Sale < ApplicationRecord #Create new tax records tax_profiles.each do |tax| - # customer.tax_profiles.each do |cus_tax| - # if cus_tax.to_i == tax.id if tax.group_type.to_s == order_source.to_s - if customer.customer_type.downcase == 'takeaway' - if tax.name.downcase == 'commercial tax' + # customer.tax_profiles.each do |cus_tax| + # if cus_tax.to_i == tax.id sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -538,35 +534,9 @@ class Sale < ApplicationRecord sale_tax.inclusive = tax.inclusive sale_tax.save - end - else - sale_tax = SaleTax.new(:sale => self) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate - - # substract , to give after discount - total_tax = total_taxable - self.total_discount - #include or execulive - if tax.inclusive - rate = tax.rate - divided_value = (100 + rate)/rate - sale_tax.tax_payable_amount = total_tax / divided_value - else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 - total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount - end - - #new taxable amount is standard rule for step by step - if shop.calc_tax_order - total_taxable = total_taxable + sale_tax.tax_payable_amount - end - - sale_tax.inclusive = tax.inclusive - sale_tax.save - end + # end + # end end - # end - # end end self.total_tax = total_tax_amount end diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 477cdca6..b1c9dde6 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -1,4 +1,4 @@ -`
+
@@ -99,52 +99,21 @@ - Tax - -
-
-
- - -
-
- -
-
- - -
-
- -
-
- - -
-
- -
-
- - -
-
-
-
+ <% if !@account_arr.empty? %> + Tax + (<% @i = 0 + @account_arr.each do |ct| %> + <%=ct.tax_name%> + <% if @account_arr.count != @i+1%> + + <% @i =+1 %> + <%end%> + <%end %>) + <% else %> + No Tax + <% end %>
+ - <%= number_with_precision(@sale_data.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> + <%= number_with_precision(@sale_data.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> Rounding Adj: @@ -574,6 +543,61 @@
+ + +

Card Tap

@@ -719,6 +743,8 @@ var customer_name = "<%= @customer.name %>"; var credit = $('#credit').text(); var card = $('#card').text(); + var tax_type = $("input:radio[name=tax_type]:checked").val(); + if (credit <= 0) { calculate_member_discount(sale_id); } @@ -727,7 +753,7 @@ var customer_name = "<%= @customer.name %>"; $('#pdfModal').focus() }).modal({show : true, backdrop : false, keyboard : false}); $.ajax({type: "POST", url: "<%= origami_payment_cash_path %>", - data: "cash="+ cash + "&sale_id=" + sale_id + "&type=" + cashier_type, + data: "cash="+ cash + "&sale_id=" + sale_id + "&type=" + cashier_type + "&tax_type=" + tax_type, success:function(result){ /* start delete receipt no in first bill*/ if(($("#receipt_no").html()!=undefined) && ($("#receipt_no").html()!="")){ @@ -1384,4 +1410,41 @@ var customer_name = "<%= @customer.name %>"; } }); } + + /* Start function for tax changable */ + $(".change_tax").on("click",function(){ + $("#change_taxModal").modal({show: true, backdrop: false, keyboard: false}); + }); + + $("button[name=tax_type]").on("click", function(){ + var type = $(this).attr("data-value"); + var cashier_type = '<%= @cashier_type %>'; + var sale_id = $('#sale_id').text(); + console.log(type); + swal({ + title: "Alert", + text: "Are you sure want to change tax?", + type: "warning", + showCancelButton: true, + confirmButtonColor: "#DD6B55", + confirmButtonText: "Yes, change it!", + closeOnConfirm: false + }, function (isConfirm) { + if (isConfirm) { + $.ajax({ + type: "POST", + url: "/origami/payment/"+cashier_type+"/change_tax", + data: {sale_id: sale_id, cashier_type: cashier_type, tax_type: type}, + success:function(data){ + if(data.status){ + window.location.href = '/origami/sale/'+sale_id+'/'+cashier_type+'/payment'; + } + } + }); + }else{ + swal.close(); + } + }); + }); + /* End function for tax changable */ diff --git a/config/routes.rb b/config/routes.rb index 7f776da0..5f213d33 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -199,6 +199,8 @@ scope "(:locale)", locale: /en|mm/ do post 'payment/junctionpay' => 'junctionpay#create' post 'payment/dinga' => 'dinga#create' + post 'payment/:type/change_tax' => 'payments#change_tax', :defaults => {:format => 'json'} + get 'sale/:sale_id/:type/payment/credit_payment' => "credit_payments#index" get 'sale/:sale_id/:type/payment/others_payment' => "others_payments#index" get 'sale/:sale_id/:type/payment/others_payment/MPU' => "mpu#index"