From 51bb2d0fcfd90fbcccc1f9ae140b6cc844fcc6dc Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Tue, 4 Aug 2020 11:52:35 +0630 Subject: [PATCH 1/5] change tax after first bill --- app/views/origami/home/show.html.erb | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index 5e94f364..b791527b 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -818,10 +818,8 @@ if ($("#server_mode").val() != "cloud") { // first bill not used in cloud if (discount) { if(checkReceiptNoInFirstBillData(receipt_no,"")){ - $("button.change_tax").hide(); $("#pay").show(); }else{ - $("button.change_tax").show(); $("#pay").hide(); } } From 7aef3d7bac97c17cf3cdbfbef190a43556f49824 Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Wed, 12 Aug 2020 14:34:53 +0630 Subject: [PATCH 2/5] daily sale net sales & tax --- .../reports/dailysale_controller.rb | 2 +- app/models/sale.rb | 17 ++++- app/views/reports/dailysale/index.html.erb | 67 ++++++++++--------- app/views/reports/dailysale/index.xls.erb | 52 ++++++++------ 4 files changed, 83 insertions(+), 55 deletions(-) diff --git a/app/controllers/reports/dailysale_controller.rb b/app/controllers/reports/dailysale_controller.rb index 71159e3b..4cc1bb81 100755 --- a/app/controllers/reports/dailysale_controller.rb +++ b/app/controllers/reports/dailysale_controller.rb @@ -4,7 +4,7 @@ class Reports::DailysaleController < BaseReportController def index from, to = get_date_range_from_params @sale_data = Sale.daily_sales_list(from,to) - @tax = SaleTax.get_tax(from,to) + @tax_profiles = TaxProfile.group(:name).order(:order_by).pluck(:name) @from = from @to = to @payment_methods = PaymentMethodSetting.where("is_active='1'").pluck("payment_method") diff --git a/app/models/sale.rb b/app/models/sale.rb index 30a8fcc5..d0b9c90a 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -754,6 +754,8 @@ class Sale < ApplicationRecord def self.daily_sales_list(from,to) payment_methods = SalePayment.where.not(payment_method: ['cash', 'creditnote', 'foc']).distinct.pluck(:payment_method) + tax_profiles = TaxProfile.group(:name).order(:order_by).pluck(:name) + sales = select(Sale.column_names) .select("#{payment_methods.map { |method| "SUM(case when (sale_payments.payment_method='#{method}') then sale_payments.payment_amount else 0 end) as `#{method == 'paypar' ? 'redeem' : method}`"}.push('').join(', ')} SUM(case when (sale_payments.payment_method='cash') then sale_payments.payment_amount else 0 end) as cash_amount, @@ -764,6 +766,15 @@ class Sale < ApplicationRecord .where("(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ", 'completed', 'void', from, to) .group("sale_id").to_sql + sale_taxes = Sale.select('sales.sale_id, sale_taxes.tax_name') + .joins(:sale_taxes) + .where('(sale_status = ? OR sale_status = ?) AND sales.receipt_date between ? AND ? ', 'completed', 'void', from, to) + .group('sale_id') + + if tax_profiles.present? + sale_taxes = sale_taxes.select(tax_profiles.map { |name| "SUM(case when (sale_taxes.tax_name = '#{name}') then sale_taxes.tax_payable_amount else 0 end) as `#{name.parameterize}`"}.join(', ')) + end + daily_total = connection.select_all("SELECT IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as grand_total, IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) as total_sale, @@ -772,8 +783,9 @@ class Sale < ApplicationRecord IFNULL(SUM(case when (sale_status='completed') then amount_changed else 0 end),0) as total_change_amount, IFNULL(SUM(case when (sale_status='void') then grand_total else 0 end),0) as void_amount, IFNULL(SUM(case when (sale_status='completed') then rounding_adjustment else 0 end),0) as rounding_adj, - IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21 as tax, - (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) - (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0) / 21) as net_sale, + #{tax_profiles.map { |name| "SUM(`#{name.parameterize}`) as `#{name.parameterize}`"}.push('').join(', ') if tax_profiles.present?} + IFNULL(SUM(case when (sale_status='completed') then total_tax else 0 end),0) as tax, + (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) - (IFNULL(SUM(case when (sale_status='completed') then total_tax else 0 end),0)) as net_sale, (IFNULL(SUM(case when (sale_status='completed') then grand_total else 0 end),0)) + (IFNULL(SUM(case when (sale_status='completed') then total_discount else 0 end),0)) as gross_sale, CAST((CONVERT_TZ(receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, #{payment_methods.map { |method| pm = method == 'paypar' ? 'redeem' : method; "SUM(`#{pm}`) as `#{pm}`"}.push('').join(', ')} @@ -783,6 +795,7 @@ class Sale < ApplicationRecord FROM ( #{sales} ) as s + JOIN (#{sale_taxes.to_sql}) AS st ON s.sale_id = st.sale_id GROUP BY DATE(CONVERT_TZ(receipt_date,'+00:00','+06:30'))").to_hash.map(&:symbolize_keys) return daily_total end diff --git a/app/views/reports/dailysale/index.html.erb b/app/views/reports/dailysale/index.html.erb index 12e6d236..0b31e2ed 100755 --- a/app/views/reports/dailysale/index.html.erb +++ b/app/views/reports/dailysale/index.html.erb @@ -24,7 +24,7 @@ - + <% @count = 1 %> <% @payment_methods.each_slice(10) do |slice| %> @@ -72,13 +72,11 @@ - - + + + + - <% if @tax.blank? %> - - - <% end %> @@ -86,22 +84,21 @@ <% @payment_methods.each do |method| %> <% end %> - - + <% if @tax_profiles.present? %> + <% @tax_profiles.each do |name| %> + + <% end %> + <% end %> + - <% if @tax.blank? %> - - - <% end %> - <% unless @sale_data.blank? %> @@ -148,12 +145,16 @@ + + <% if @tax_profiles.present? %> + <% @tax_profiles.each do |name| %> + + <% end %> + <% end %> + + - <% if @tax.blank? %> - - - <% end %> <% count = count + 1 %> @@ -172,33 +173,37 @@ - - - <% if @tax.blank? %> - - + + <% if @tax_profiles.present? %> + <% @tax_profiles.each do |name| %> + + <% end %> <% end %> + + + <% total_tax = 0 %> <% net = 0 %> - <% unless @tax.blank? %> - <% @tax.each do |tax| - total_tax += tax.tax_amount.to_f %> - - - - + <% if @tax_profiles.present? %> + <% @tax_profiles.each do |name| %> + + + + <% end %> <% net = grand_total %> <% net = net - rounding_adj%> <% net = net - total_tax %> - + <% else %> diff --git a/app/views/reports/dailysale/index.xls.erb b/app/views/reports/dailysale/index.xls.erb index 98cfe853..9c1bee4f 100755 --- a/app/views/reports/dailysale/index.xls.erb +++ b/app/views/reports/dailysale/index.xls.erb @@ -22,6 +22,7 @@ + @@ -38,13 +39,14 @@ + <% if @tax_profiles.present? %> + <% @tax_profiles.each do |name| %> + + <% end %> + <% end %> + - <% if @tax.blank? %> - - - <% end %> - <% unless @sale_data.blank? %> @@ -90,12 +92,16 @@ + + <% if @tax_profiles.present? %> + <% @tax_profiles.each do |name| %> + + <% end %> + <% end %> + + - <% if @tax.blank? %> - - - <% end %> <% count = count + 1 %> @@ -114,12 +120,15 @@ + <% if @tax_profiles.present? %> + <% @tax_profiles.each do |name| %> + + <% end %> + <% end %> + + - <% if @tax.blank? %> - - - <% end %> @@ -127,20 +136,21 @@ <% total_tax = 0 %> <% net = 0 %> - <% unless @tax.blank? %> - <% @tax.each do |tax| - total_tax += tax.tax_amount.to_f %> - - - - + <% if @tax_profiles.present? %> + <% @tax_profiles.each do |name| %> + + + + <% end %> <% net = grand_total %> <% net = net - rounding_adj%> <% net = net - total_tax %> - + <% else %> From 590b0aac3b1d2fb8f11db41be272918fc90cfc0d Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Tue, 18 Aug 2020 17:30:27 +0630 Subject: [PATCH 3/5] fix table booking --- app/controllers/origami/sales_controller.rb | 2 +- app/models/dining_facility.rb | 8 +-- app/views/origami/home/show.html.erb | 56 +++++++++++---------- 3 files changed, 35 insertions(+), 31 deletions(-) diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb index 27f300d8..9ec6f843 100755 --- a/app/controllers/origami/sales_controller.rb +++ b/app/controllers/origami/sales_controller.rb @@ -30,7 +30,7 @@ class Origami::SalesController < BaseOrigamiController Sale.transaction do table = DiningFacility.find(dining) booking = table.current_checkin_booking - + sale = Sale.find(sale_id) existing = sale.booking diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index f42545ec..96ddf2a3 100755 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -9,10 +9,10 @@ class DiningFacility < ApplicationRecord has_many :order_queue_stations, -> { where(is_active: true) }, through: :order_queue_process_by_zones has_many :bookings - has_many :current_bookings, -> { left_joins(:sale).assign.merge(Booking.where(checkout_at: nil).or(Booking.merge(Sale.where(sale_status: ['new', nil])))) }, class_name: "Booking" - has_one :current_checkin_booking, -> { left_joins(:sale).assign.merge(Sale.where(sale_status: nil)) }, class_name: "Booking" - has_one :current_checkout_booking, -> { left_joins(:sale).assign.where.not(checkout_at: nil).merge(Sale.where(sale_status: 'new')) }, class_name: "Booking" - has_one :current_reserved_booking, -> { left_joins(:sale).assign.where.not(reserved_at: nil).merge(Sale.where(sale_status: nil)) }, class_name: "Booking" + has_many :current_bookings, -> { left_joins(:sale).assign.merge(Booking.unscoped.where(checkout_at: nil).or(Booking.merge(Sale.unscoped.where(sale_status: ['new', nil])))) }, class_name: "Booking" + has_one :current_checkin_booking, -> { left_joins(:sale).assign.merge(Sale.unscoped.where(sale_status: nil)) }, class_name: "Booking" + has_one :current_checkout_booking, -> { left_joins(:sale).assign.where.not(checkout_at: nil).merge(Sale.unscoped.where(sale_status: 'new')) }, class_name: "Booking" + has_one :current_reserved_booking, -> { left_joins(:sale).assign.where.not(reserved_at: nil).merge(Sale.unscoped.where(sale_status: nil)) }, class_name: "Booking" has_many :current_sales, -> { where(sale_status: 'new').merge(Booking.assign) }, through: :bookings, class_name: "Sale", source: "sale" diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb index b791527b..35356972 100755 --- a/app/views/origami/home/show.html.erb +++ b/app/views/origami/home/show.html.erb @@ -831,6 +831,7 @@ var sale_id = this.id; window.location.href = '/origami/table/' + dining_id + "/table_invoice/" + sale_id; }) + $(".tables").on('click', function () { localStorage.setItem('dinning_type','table'); var customer_id = $(".customer-id").text(); @@ -1156,32 +1157,35 @@ }) $('#add_invoice').on('click', function () { - $("#first_bill").prop('disabled',true); - $("#pay").prop('disabled',true); - var dining_id = "<%= @dining.id %>"; - var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %> - var ajax_url = "/origami/sale/append_order"; - // var tax_type = localStorage.getItem("tax_type"); - var tax_type = $("#check_tax").val(); - $.ajax({ - type: "POST", - url: ajax_url, - data: 'dining_id=' + dining_id + "&sale_id=" + sale_id + "&tax_type=" + tax_type, - success: function (result) { - swal({ - title: "Information!", - text: "Invoice updated", - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - $("#first_bill").removeAttr('disabled'); - $("#pay").removeAttr('disabled'); - window.location.reload(); - }); - } - }); + $("#loading_wrapper").show(); + $("#add_invoice").prop('disable', true); + $("#first_bill").prop('disabled',true); + $("#pay").prop('disabled',true); + var dining_id = "<%= @dining.id %>"; + var sale_id = $("#sale_id").val(); //<%= @obj_sale.sale_id rescue "" %> + var ajax_url = "/origami/sale/append_order"; + // var tax_type = localStorage.getItem("tax_type"); + var tax_type = $("#check_tax").val(); + $.ajax({ + type: "POST", + url: ajax_url, + data: 'dining_id=' + dining_id + "&sale_id=" + sale_id + "&tax_type=" + tax_type, + success: function (result) { + swal({ + title: "Information!", + text: "Invoice updated", + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + $("#first_bill").removeAttr('disabled'); + $("#pay").removeAttr('disabled'); + window.location.reload(); + }); + $("#loading_wrapper").hide(); + } + }); }) //show cusotmer rebate amount From b10e471ece581f04ba5ab99d11e3728589c99771 Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Mon, 24 Aug 2020 10:38:13 +0630 Subject: [PATCH 4/5] credit payment 0 fixed --- app/controllers/origami/payments_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 8b5416cf..cfee4a45 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -275,7 +275,7 @@ class Origami::PaymentsController < BaseOrigamiController @payment_methods = PaymentMethodSetting.where(is_active: true).pluck(:payment_method) @cash = payments.inject(0) { |sum, payment| sum + payment[1] if payment[0] == 'cash' } - @credit = payments.inject(0) { |sum, payment| sum + payment[1] if payment[0] == 'creditnote' } + @credit = payments.inject(0) { |sum, payment| payment[0] == 'creditnote' ? sum + payment[1] : sum } @other_payments = payments.select { |payment| !['cash', 'creditnote', 'foc'].include? payment[0] }.map { |method, amount| [ @payment_methods.find { |payment_method| payment_method.parameterize == method }, amount ] } @other_payment = @other_payments.sum { |payment| payment[1] } From e49840a1592565712d7e4aec92f1a92162dc8186 Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Mon, 24 Aug 2020 14:23:22 +0630 Subject: [PATCH 5/5] add customer confirm button fixed --- app/views/origami/customers/index.html.erb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index e3ed07cb..fb1e7e14 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -9,7 +9,9 @@ --> - +
@@ -658,13 +660,14 @@ swal({ title: "Confirmation !", - text: 'Are You Sure to assign this customer' + customer + '!', + text: 'Are you sure to assign this customer' + customer + '!', showCancelButton: true, confirmButtonColor: "green", confirmButtonText: "Yes!", cancelButtonClass: 'btn btn-danger', - closeOnConfirm: false, + closeOnConfirm: true, }, function () { + $( "#loading_wrapper").show(); $.ajax({ type: "POST", url: "/origami/"+sale_id+"/"+cashier_type+"/customers/update_sale" ,
<%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%> <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to.utc.getlocal.strftime("%Y-%b-%d") rescue '-'%>
IncomeOutgoinglive_helpOutgoingTaxlive_helplive_help live_helplive_helplive_help
<%= t("views.right_panel.detail.sr") %><%= t("views.right_panel.detail.#{method}") %><%= t("views.right_panel.detail.cash_sales") %> <%= t("views.right_panel.detail.credit_sales") %> <%= t("views.right_panel.detail.void_amount") %> <%= t("views.right_panel.detail.foc_sales") %>(<%= t("views.right_panel.detail.discount") %>) <%= t("views.right_panel.detail.rnd_adj_sh") %><%= t name %><%= t("views.right_panel.detail.net_sales") %> <%= t("views.right_panel.detail.gross_sales") %> <%= t("views.right_panel.detail.total_sales") %><%= t("views.right_panel.detail.tax") %><%= t("views.right_panel.detail.net_sales") %>
(<%= number_format(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>) <%= number_format(sale[:rounding_adj], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[name.parameterize.to_sym], precision:precision.to_i,delimiter:delimiter) rescue '-' %><%= number_format(sale[:net_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(sale[:gross_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(sale[:total_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:tax], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:net_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%>
(<%= number_format(discount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>) <%= number_format(rounding_adj, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(gross_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(total_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(tax, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[name.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(gross_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(total_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%>
 
<%= tax.tax_name rescue '-'%><%= number_format(tax.tax_amount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>
<%= t name rescue '-'%> + <%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[name.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue '-'%> +
<%= t("views.right_panel.detail.net_amount") %><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-' %>
Income OutgoingTax
<%= t("views.right_panel.detail.sr") %>(<%= t("views.right_panel.detail.discount") %>) <%= t("views.right_panel.detail.rnd_adj_sh") %><%= t name %><%= t("views.right_panel.detail.net_sales") %> <%= t("views.right_panel.detail.gross_sales") %> <%= t("views.right_panel.detail.total_sales") %><%= t("views.right_panel.detail.tax") %><%= t("views.right_panel.detail.net_sales") %>
(<%= number_format(sale[:total_discount], precision:precision,delimiter:delimiter) rescue '-'%>) <%= number_format(sale[:rounding_adj].to_f, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[name.parameterize.to_sym], precision:precision.to_i,delimiter:delimiter) rescue '-' %><%= number_format(sale[:net_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(sale[:gross_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(sale[:total_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:tax], precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(sale[:net_sale], precision:precision.to_i,delimiter:delimiter) rescue '-'%>
(<%= number_format(discount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>) <%= number_format(rounding_adj, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[name.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(gross_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%> <%= number_format(total_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(tax, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(net_sale, precision:precision.to_i,delimiter:delimiter) rescue '-'%>
<%= tax.tax_name rescue '-'%><%= number_format(tax.tax_amount, precision:precision.to_i,delimiter:delimiter) rescue '-'%>
<%= t name rescue '-'%> + <%= number_format(@sale_data.inject(0.0.to_d) { |sum, sale| sum + sale[name.parameterize.to_sym] }, precision:precision.to_i,delimiter:delimiter) rescue '-'%> +
<%= t("views.right_panel.detail.net_amount") %><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%><%= number_format(net, precision:precision.to_i,delimiter:delimiter) rescue '-'%>