From 87906989a3e30fb1ce0e59ad8e66a694394001e7 Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Fri, 21 Aug 2020 14:53:15 +0630 Subject: [PATCH 01/15] added customer report --- README.md | 3 + .../reports/customer_controller.rb | 58 ++++ app/models/sale.rb | 30 ++ app/views/layouts/_left_sidebar.html.erb | 3 + .../_shift_sale_report_filter.html.erb | 144 +++++++++ app/views/reports/customer/index.html.erb | 286 ++++++++++++++++++ app/views/reports/customer/index.xls.erb | 165 ++++++++++ config/routes.rb | 1 + 8 files changed, 690 insertions(+) create mode 100644 app/controllers/reports/customer_controller.rb create mode 100755 app/views/reports/customer/_shift_sale_report_filter.html.erb create mode 100644 app/views/reports/customer/index.html.erb create mode 100644 app/views/reports/customer/index.xls.erb diff --git a/README.md b/README.md index 63ba995a..981a0335 100755 --- a/README.md +++ b/README.md @@ -287,6 +287,9 @@ settings/lookups => {type:show_total_before_tax, name:Show Total Before Tax, val For Using Staff Meal settings/lookups => { type:customer_type, name: Staff, value:Staff } +For Membership Type +settings/lookups => { type:membership_type, name: Timecity staff, value:8 } + - ToDo list 1. Migration diff --git a/app/controllers/reports/customer_controller.rb b/app/controllers/reports/customer_controller.rb new file mode 100644 index 00000000..b623d1e0 --- /dev/null +++ b/app/controllers/reports/customer_controller.rb @@ -0,0 +1,58 @@ +class Reports::CustomerController < BaseReportController + authorize_resource :class => false + def index + @membership_type = Lookup.where(lookup_type: 'membership_type') + from, to = get_date_range_from_params + customer_filter = params[:customer] + + @shift_sale_range = '' + + @shift = '' + if params[:shift_name].to_i != 0 + + @shift_sale_range = Sale.get_by_shift_sale_by_item(from,to,Sale::SALE_STATUS_COMPLETED) + + @shift_sale = ShiftSale.find(params[:shift_name]) + if to.blank? + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',@shift_sale.shift_started_at) + else + if @shift_sale.shift_closed_at.blank? + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL',@shift_sale.shift_started_at) + else + @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',@shift_sale.shift_started_at, @shift_sale.shift_closed_at) + end + end + end + + @lookup = Lookup.find_by_lookup_type('reprint_receipt') + if @lookup.nil? + @lookup = Lookup.create_reprint_receipt_lookup + end + if params[:membership_type] == "0" + membership_type = '' + else + membership_type = params[:membership_type] + end + @sale_data = Sale.get_shift_sales_by_customer(@shift_sale_range, @shift, from, to, membership_type, customer_filter) + @sale_taxes = Sale.get_separate_tax(@shift_sale_range, @shift, from, to, nil) + @tax_profiles = TaxProfile.group('name').order('order_by asc') #.limit(2) + + @from = from + @to = to + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + if @shift.present? + @shift.each do |sh| + @shift_from = sh.shift_started_at.nil? ? '-' : sh.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = sh.shift_closed_at.nil? ? '-' : sh.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = sh + end + end + + respond_to do |format| + format.html + format.xls + end + end + + end diff --git a/app/models/sale.rb b/app/models/sale.rb index d0b9c90a..247ef00c 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1214,6 +1214,36 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range, shift, from, to, paymen return query end +def self.get_shift_sales_by_customer(shift_sale_range, shift, from, to, membership_type, customer_filter) + ## => left join -> show all sales although no orders + query = Sale.includes(:sale_items).select("sales.*, sale_payments.*") + .select("customers.customer_id, customers.name as customer_name,customers.membership_type as membership_type, dining_facilities.name, dining_facilities.type") + .joins("INNER JOIN sale_payments ON sale_payments.sale_id = sales.sale_id") + .joins("INNER JOIN bookings ON bookings.sale_id = sales.sale_id") + .joins("LEFT JOIN dining_facilities ON dining_facilities.id = bookings.dining_facility_id") + .completed.where.not(total_amount: 0) + .group("sales.sale_id") + + if customer_filter.present? + query = query.joins(sanitize_sql_array(["INNER JOIN customers ON customers.customer_id = sales.customer_id AND " + + "customers.name LIKE :filter", filter: "%#{customer_filter}%"])) + else + query = query.joins(:customer) + end + if !membership_type.blank? + query = query.where("customers.membership_type = (?)", membership_type) + end + + if shift.present? + query = query.where("sales.shift_sale_id in (?)", shift.to_a) + elsif shift_sale_range.present? + query = query.where("sales.shift_sale_id in (?)", shift_sale_range.to_a) + else + query = query.where("sales.receipt_date between ? and ?", from, to) + end + return query.group_by(&:membership_type) +end + def self.get_shift_sales_by_receipt_no_detail(shift_sale_range, shift, from, to, payment_type, customer_filter) ## => left join -> show all sales although no orders puts customer_filter diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index 4ca2f1ad..78e4c06a 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -324,6 +324,9 @@
  • Void Sales +
  • +
  • + Customer Sales
  • Wastes & Spoilages diff --git a/app/views/reports/customer/_shift_sale_report_filter.html.erb b/app/views/reports/customer/_shift_sale_report_filter.html.erb new file mode 100755 index 00000000..35819152 --- /dev/null +++ b/app/views/reports/customer/_shift_sale_report_filter.html.erb @@ -0,0 +1,144 @@ +
    + <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> + <% if period_type != false %> +
    +
    + + +
    + +
    + + +
    + + <% if defined? @membership_type %> +
    + + + +
    + <% end %> + +
    + + + +
    +
    + + +
    +
    + + +
    +
    + +
    +
    + <% end %> + + <% end %> +
    + + diff --git a/app/views/reports/customer/index.html.erb b/app/views/reports/customer/index.html.erb new file mode 100644 index 00000000..328de17f --- /dev/null +++ b/app/views/reports/customer/index.html.erb @@ -0,0 +1,286 @@ + + +
    +
    + + + <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_customer_index_path} %> +
    + + + + + + + + +
    +
    + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + <% @tax_profiles.each do |tax| %> + + <% end %> + + + + + + + <% t_grand_total = 0 %> + <% t_old_grand_total = 0 %> + <% t_total_sum = 0 %> + <% t_discount_amt = 0 %> + <% t_rounding_adj = 0%> + + <% if !@sale_data.nil? %> + + <% @sale_data.each do |member_group| %> + <% grand_total = 0 %> + <% old_grand_total = 0 %> + <% total_tax = [] %> + <% total_sum = 0 %> + <% discount_amt = 0 %> + <% rounding_adj = 0%> + + + <%if member_group[0].nil?%> + + <%else%> + + <%end%> + + + <% member_group[1].each do |result|%> + <% grand_total += result.grand_total.to_f %> + <% t_grand_total += result.grand_total.to_f %> + <% old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f %> + <% t_old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f%> + <% total_sum += result.total_amount.to_f %> + <% t_total_sum += result.total_amount.to_f %> + <% discount_amt += result.total_discount.to_f %> + <% t_discount_amt += result.total_discount.to_f %> + <% rounding_adj += result.rounding_adjustment.to_f %> + <% t_rounding_adj += result.rounding_adjustment.to_f %> + + + + + + + + + <% @tax_profiles.each do |tax| %> + <%tax_value=0%> + <% if sale_tax = result.sale_taxes.find { |sale_tax| sale_tax.tax_name == tax.name } %> + <%tax_value=sale_tax.tax_payable_amount%> + + <% else %> + + <% end %> + <%total_tax << { + tax.name => tax_value + }%> + <% end %> + + + + + <% end %> + + <% total_tax = total_tax.reduce {|acc, h| acc.merge(h) {|_,v1,v2| v1 + v2 }}%> + + + + <% @tax_profiles.each do |tax| %> + <%if total_tax.has_key?(tax.name)%> + + <%end%> + <% end %> + + + + + + + + <%end%> + + + + + + <% @tax_profiles.each do |tax| %> + + <% end %> + + + + + <%end%> + + + + + <% @tax_profiles.each do |tax| %> + <% if sale_tax = @sale_taxes.find { |sale_tax| sale_tax.tax_name == tax.name } %> + + <% else %> + + <% end %> + <% end %> + + + + + +
    <%= 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.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
    <%= t("views.right_panel.detail.dining") %><%= t("views.right_panel.detail.receipt_no") %><%= t :customer %><%= t :cashier %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> <%= tax.name %><%= t("views.right_panel.detail.grand_total") %><%= t("views.right_panel.detail.rnd_adj_sh") %><%= t("views.right_panel.detail.grand_total") %> +
    + <%= t("views.right_panel.detail.rnd_adj_sh") %> +
    Group Type : Normal Group Type : <%= Lookup.where(:lookup_type=>'membership_type', :value=>member_group[0]).last.name %>
    + <%if result.type %> + <%= result.type %> - <%= result.name %> + <% else %> + - + <% end %> + <%= result.receipt_no rescue '-' %> <%= result.customer_name rescue '-' %><%= result.cashier_name rescue '-' %><%= number_format(result.total_amount, precision: precision.to_i, delimiter: delimiter) %><%= number_format(result.total_discount, precision: precision.to_i, delimiter: delimiter) rescue '0' %><%= number_format(sale_tax.tax_payable_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> <%= number_format(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(result.grand_total - result.rounding_adjustment, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(result.rounding_adjustment.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(result.grand_total, precision: precision.to_i, delimiter: delimiter) rescue '-' %>
     <%= number_format(total_sum, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(discount_amt, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(total_tax[tax.name], precision: precision.to_i, delimiter: delimiter) rescue '-' %> <%= number_format(old_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '0' %><%= number_format(rounding_adj.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %>
     
     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %><%= tax.name %><%= t("views.right_panel.detail.grand_total") %><%= t("views.right_panel.detail.rnd_adj_sh") %><%= t("views.right_panel.detail.grand_total") %> +
    + <%= t("views.right_panel.detail.rnd_adj_sh") %> +
     <%= number_format(t_total_sum, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(t_discount_amt, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(sale_tax.st_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> <%= number_format(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(t_old_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '0' %><%= number_format(t_rounding_adj.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(t_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %>
    +
    +
    +
    +
    + + diff --git a/app/views/reports/customer/index.xls.erb b/app/views/reports/customer/index.xls.erb new file mode 100644 index 00000000..9ebfe63a --- /dev/null +++ b/app/views/reports/customer/index.xls.erb @@ -0,0 +1,165 @@ + + + + + + + +
    +
    +
    +
    + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + <% @tax_profiles.each do |tax| %> + + <% end %> + + + + + + + + + <% t_grand_total = 0 %> + <% t_old_grand_total = 0 %> + <% t_total_sum = 0 %> + <% t_discount_amt = 0 %> + <% t_rounding_adj = 0%> + + <% if @sale_data %> + <% @sale_data.each do |member_group| %> + <% grand_total = 0 %> + <% old_grand_total = 0 %> + <% total_tax = [] %> + <% total_sum = 0 %> + <% discount_amt = 0 %> + <% rounding_adj = 0%> + + + <%if member_group[0].nil?%> + + <%else%> + + <%end%> + + + <% member_group[1].each do |result|%> + <% grand_total += result.grand_total.to_f %> + <% t_grand_total += result.grand_total.to_f %> + <% old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f %> + <% t_old_grand_total += result.grand_total.to_f - result.rounding_adjustment.to_f%> + <% total_sum += result.total_amount.to_f %> + <% t_total_sum += result.total_amount.to_f %> + <% discount_amt += result.total_discount.to_f %> + <% t_discount_amt += result.total_discount.to_f %> + <% rounding_adj += result.rounding_adjustment.to_f %> + <% t_rounding_adj += result.rounding_adjustment.to_f %> + + + + + + + + + <% @tax_profiles.each do |tax| %> + <%tax_value=0%> + <% if sale_tax = result.sale_taxes.find { |sale_tax| sale_tax.tax_name == tax.name } %> + <%tax_value=sale_tax.tax_payable_amount%> + + <% else %> + + <% end %> + <%total_tax << { + tax.name => tax_value + }%> + <% end %> + + + + + <% end %> + + <% total_tax = total_tax.reduce {|acc, h| acc.merge(h) {|_,v1,v2| v1 + v2 }}%> + + + + <% @tax_profiles.each do |tax| %> + <%if total_tax.has_key?(tax.name)%> + + <%end%> + <% end %> + + + + + + + + <%end%> + + + + + + <% @tax_profiles.each do |tax| %> + + <% end %> + + + + + <%end%> + + + + + <% @tax_profiles.each do |tax| %> + <% if sale_tax = @sale_taxes.find { |sale_tax| sale_tax.tax_name == tax.name } %> + + <% else %> + + <% end %> + <% end %> + + + + + +
    <%= 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.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
    <%= t("views.right_panel.detail.dining") %><%= t("views.right_panel.detail.receipt_no") %><%= t :customer %><%= t :cashier %><%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %> <%= tax.name %><%= t("views.right_panel.detail.grand_total") %><%= t("views.right_panel.detail.rnd_adj_sh") %><%= t("views.right_panel.detail.grand_total") %> +
    + <%= t("views.right_panel.detail.rnd_adj_sh") %> +
    Group Type : Normal Group Type : <%= Lookup.where(:lookup_type=>'membership_type', :value=>member_group[0]).last.name %>
    + <%if result.type %> + <%= result.type %> - <%= result.name %> + <% else %> + - + <% end %> + <%= result.receipt_no rescue '-' %> <%= result.customer_name rescue '-' %><%= result.cashier_name rescue '-' %><%= number_format(result.total_amount, precision: precision.to_i, delimiter: delimiter) %><%= number_format(result.total_discount, precision: precision.to_i, delimiter: delimiter) rescue '0' %><%= number_format(sale_tax.tax_payable_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> <%= number_format(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(result.grand_total - result.rounding_adjustment, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(result.rounding_adjustment.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(result.grand_total, precision: precision.to_i, delimiter: delimiter) rescue '-' %>
     <%= number_format(total_sum, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(discount_amt, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(total_tax[tax.name], precision: precision.to_i, delimiter: delimiter) rescue '-' %> <%= number_format(old_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '0' %><%= number_format(rounding_adj.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %>
     
     <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.amount") %><%= t("views.right_panel.detail.discount") %> <%= t("views.right_panel.detail.amount") %><%= tax.name %><%= t("views.right_panel.detail.grand_total") %><%= t("views.right_panel.detail.rnd_adj_sh") %><%= t("views.right_panel.detail.grand_total") %> +
    + <%= t("views.right_panel.detail.rnd_adj_sh") %> +
     <%= number_format(t_total_sum, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(t_discount_amt, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(sale_tax.st_amount, precision: precision.to_i, delimiter: delimiter) rescue '-' %> <%= number_format(0, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(t_old_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '0' %><%= number_format(t_rounding_adj.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %><%= number_format(t_grand_total.to_f, precision: precision.to_i, delimiter: delimiter) rescue '-' %>
    +
    +
    +
    +
    + + diff --git a/config/routes.rb b/config/routes.rb index 5fb08e4c..11b3fe90 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -546,6 +546,7 @@ scope "(:locale)", locale: /en|mm/ do namespace :reports do resources :receipt_no resources :receipt_no_detail + resources :customer, :only => [:index, :show] resources :dailysale, :only => [:index, :show] resources :saleitem, :only => [:index, :show] resources :hourly_saleitem, :only => [:index, :show] From 9d1f5908ce8676b71a3cdc777f66ca4c52a7c51c Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Wed, 26 Aug 2020 14:41:02 +0630 Subject: [PATCH 02/15] change server mode --- config/secrets.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/secrets.yml b/config/secrets.yml index 9eabc5ac..069b1403 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -13,7 +13,7 @@ development: secret_key_base: b61d85f8ed2a1a9e0eeece3443b3e8f838d002cc1d9f32115d8e93db920e2957adfedc57501d44741211538f3108b742cdeada87d5bfae796c53da1f90a3cd61 sx_provision_url: connect.smartsales.asia/api #connect.smartsales.dev/api #connect.smartsales.asia/api #provision.zsai.ws/api - server_mode: cloud + server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L From 1b7a970f1d3bc4de91a6003866f4fa356ee16be9 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Thu, 27 Aug 2020 17:09:22 +0630 Subject: [PATCH 03/15] fix variable --- app/controllers/home_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 4f161fb4..846640f3 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -27,7 +27,7 @@ private crm_root_path elsif current_user.role == "account" reports_dailysale_index_path - elsif @current_user.role == "kitchen" + elsif current_user.role == "kitchen" oqs_root_path else login_path From d4d27dfc1ec0aca2d8f50f0778c8c61ab0b2e95b Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Fri, 28 Aug 2020 14:52:57 +0630 Subject: [PATCH 04/15] use oqs printer name --- app/models/printer/order_queue_printer.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 84ef703c..e254a775 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -28,7 +28,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end else ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - queue: oqs.station_name, + queue: oqs.printer_name, unique_code: print_settings.unique_code, print_copies: print_settings.print_copies, data: { @@ -73,7 +73,7 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker end else ActionCable.server.broadcast("print_channel_#{Shop.current_shop.shop_code}", - queue: oqs.station_name, + queue: oqs.printer_name, unique_code: print_settings.unique_code, print_copies: print_settings.print_copies, data: { From f8b56cf48a1bc889a182dad1faf86a112601af28 Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Tue, 1 Sep 2020 12:52:04 +0630 Subject: [PATCH 05/15] seed generator model name --- app/models/seed_generator.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index 8118b272..ee99820f 100755 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -1,9 +1,6 @@ class SeedGenerator < ApplicationRecord # Generate ID for Tables def self.generate_id(model, prefix) - # model_name = self.get_model_name(model) - model_name = model - prefix ||= '' prefix << '-' if prefix.present? @@ -17,15 +14,12 @@ class SeedGenerator < ApplicationRecord prefix << shop.shop_code end - seed = self.update_seed(model_name) + seed = self.update_seed(model) length = 16 - prefix.length prefix + seed.to_s.rjust(length, '0') end def self.generate_ids(model, prefix, count = 1) - # model_name = self.get_model_name(model) - model_name = model - prefix ||= '' prefix << '-' if prefix.present? @@ -39,7 +33,7 @@ class SeedGenerator < ApplicationRecord prefix << shop.shop_code end - start = self.update_seed(model_name, count) + start = self.update_seed(model, count) stop = start + count - 1 length = 16 - prefix.length (start..stop).map { |c| prefix + c.to_s.rjust(length, '0') } @@ -129,7 +123,8 @@ class SeedGenerator < ApplicationRecord def self.update_seed(model, count = 1) SeedGenerator.transaction do - seed = SeedGenerator.lock.find_by_model(model) + seed = SeedGenerator.lock.find_by_model(get_model_name(model)) || + SeedGenerator.lock.find_by_model(model) seed.next = seed.next + (count * seed.increase_by) seed.current = seed.next - seed.increase_by seed.save! From fa630fd5270d03ced06c02d2701c3e30c71357e7 Mon Sep 17 00:00:00 2001 From: yarzar_code Date: Wed, 2 Sep 2020 17:16:01 +0630 Subject: [PATCH 06/15] nfc add customer fixed --- app/views/crm/customers/_new_form.html.erb | 6 +- app/views/crm/customers/index.html.erb | 6 +- app/views/origami/customers/index.html.erb | 62 +++---- app/views/origami/dinga/index.html.erb | 108 ++++++----- app/views/origami/paymal/index.html.erb | 118 ++++++------ app/views/origami/payments/show.html.erb | 197 ++++++++++----------- 6 files changed, 241 insertions(+), 256 deletions(-) diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index e401aef6..7971ba72 100644 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -262,10 +262,7 @@ $("#paypar_account_no").on('focus', function(e){ if($(this).val() == ''){ $("#sxModal").show(); - setTimeout(function(){ - getCardNo(); - $("#sxModal").hide(); - },100); + getCardNo(); } }); @@ -283,6 +280,7 @@ // get CardNo from Java function setCardNo(cardNo){ + $("#sxModal").hide(); check_member = localStorage.getItem("member_card"); if(cardNo.length == 16){ if(check_member == "true"){ diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 815335f2..a5462b1d 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -173,11 +173,7 @@ localStorage.setItem("member_card",true); var cardNo = ""; $("#sxModal").show(); - setTimeout(function(){ - getCardNo(); - $("#sxModal").hide(); - $("#filter_form").submit(); - },100); + getCardNo(); }); diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index fb1e7e14..fb804f5b 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -396,10 +396,7 @@ $("#paypar_account_no").on('focus', function(e){ if($(this).val() == ''){ $("#sxModal").show(); - setTimeout(function(){ - getCardNo(); - $("#sxModal").hide(); - },100); + getCardNo(); } }); @@ -416,37 +413,34 @@ var sale_id = $("#sale_id").val() || 0; var customer_mamber_card_no = 0; $("#sxModal").show(); - setTimeout(function(){ - getCardNo(); - $("#sxModal").hide(); - customer_mamber_card_no = $("#search").val(); - - if(sale_id != 0 && customer_mamber_card_no != 0){ - $.ajax({ - type: "POST", - url: "/origami/"+sale_id+"/get_customer" , - data: { filter : customer_mamber_card_no ,type :"card"}, - dataType: "json", - success: function(data) { - if (data[0].customer_id == false) { - swal("Alert!", data[0].message, "error"); - // $.alert({ - // title: 'Alert!', - // content: data[0].message, - // type: 'red', - // typeAnimated: true, - // btnClass: 'btn-danger', - // }); - }else{ - customer_id = data[0].customer_id; - customer_name = data[0].name; - update_sale(customer_id, customer_name,sale_id); - } + getCardNo(); + customer_mamber_card_no = $("#search").val(); + if(sale_id != 0 && customer_mamber_card_no != 0){ + $.ajax({ + type: "POST", + url: "/origami/"+sale_id+"/get_customer" , + data: { filter : customer_mamber_card_no ,type :"card"}, + dataType: "json", + success: function(data) { + if (data[0].customer_id == false) { + swal("Alert!", data[0].message, "error"); + // $.alert({ + // title: 'Alert!', + // content: data[0].message, + // type: 'red', + // typeAnimated: true, + // btnClass: 'btn-danger', + // }); + }else{ + customer_id = data[0].customer_id; + customer_name = data[0].name; + update_sale(customer_id, customer_name,sale_id); } - }); - } - },100); + + } + }); + } }); /*new customer UI func:*/ @@ -495,12 +489,14 @@ // get CardNo from Java function setCardNo(cardNo){ + $("#sxModal").hide(); check_member = localStorage.getItem("member_card"); if(cardNo.length == 16){ if(check_member == "true"){ $("#paypar_account_no").val(cardNo); $("#search").val(cardNo); $("#type").val("card"); + $("#filter_form").submit(); }else{ if($.inArray(cardNo, paypar_account_no) !== -1){ swal({ diff --git a/app/views/origami/dinga/index.html.erb b/app/views/origami/dinga/index.html.erb index 8c326ac2..fbefb5be 100644 --- a/app/views/origami/dinga/index.html.erb +++ b/app/views/origami/dinga/index.html.erb @@ -262,65 +262,62 @@ var customer_mamber_card_no = 0; $("#is_paymemberModal").hide(); - $("#sxModal").show(); - setTimeout(function(){ - getCardNo(); - $("#sxModal").hide(); - customer_mamber_card_no = $("#paypar_account_no").val(); - - if(sale_id != 0 && customer_mamber_card_no != 0){ - $.ajax({ - type: "POST", - url: "/origami/"+sale_id+"/send_account" , - data: { account_no : customer_mamber_card_no, amount : payment_amount, receipt_no : receipt_no}, - dataType: "json", - success: function(data) { - console.log(data) - if (data.status == true) { - var valid_amount = parseFloat(data.old_balance_amount) - parseFloat(data.reload_amount); - $("#valid_amount").val((valid_amount > 0) ? parseFloat(valid_amount) : 0); + $("#sxModal").show(); + getCardNo(); + customer_mamber_card_no = $("#paypar_account_no").val(); - $.ajax({ - type: "POST", - url: "<%=origami_payment_dinga_path%>", - data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref,account_no :customer_mamber_card_no}, - success: function(result){ - console.log(result) - if(result.status == true){ - swal({ - title: "Information!", - text: result.message, - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; - }); + if(sale_id != 0 && customer_mamber_card_no != 0){ + $.ajax({ + type: "POST", + url: "/origami/"+sale_id+"/send_account" , + data: { account_no : customer_mamber_card_no, amount : payment_amount, receipt_no : receipt_no}, + dataType: "json", + success: function(data) { + console.log(data) + if (data.status == true) { + var valid_amount = parseFloat(data.old_balance_amount) - parseFloat(data.reload_amount); + $("#valid_amount").val((valid_amount > 0) ? parseFloat(valid_amount) : 0); - }else{ - swal ( "Opps",result.message ,"warning" ); - } + $.ajax({ + type: "POST", + url: "<%=origami_payment_dinga_path%>", + data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref,account_no :customer_mamber_card_no}, + success: function(result){ + console.log(result) + if(result.status == true){ + swal({ + title: "Information!", + text: result.message, + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; + }); + + }else{ + swal ( "Opps",result.message ,"warning" ); + } + } + }); + }else{ + swal({ + title: 'Oops', + text: data.message.toString(), + type: 'error', + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment/others_payment/DINGA"; + }); } - }); - }else{ - swal({ - title: 'Oops', - text: data.message.toString(), - type: 'error', - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment/others_payment/DINGA"; - }); - } - } - }); - } - },100); + } + }); + } }); // Read NFC card no from java @@ -330,6 +327,7 @@ // get CardNo from Java function setCardNo(cardNo){ + $("#sxModal").hide(); if(cardNo.length == 16){ $("#paypar_account_no").val(cardNo); } diff --git a/app/views/origami/paymal/index.html.erb b/app/views/origami/paymal/index.html.erb index 802c1ce4..82dae2de 100644 --- a/app/views/origami/paymal/index.html.erb +++ b/app/views/origami/paymal/index.html.erb @@ -247,8 +247,8 @@ }); // Read Card Reader - $(".btn_member").on('click', function(){ - var cardNo = ""; + $(".btn_member").on('click', function(){ + var cardNo = ""; var sale_id = $("#sale_id").text() || 0; var receipt_no = $("#receipt_no").val() || ""; @@ -256,67 +256,66 @@ var payment_amount = parseFloat($("#used_amount").text()); $("#is_paymemberModal").hide(); - $("#sxModal").show(); - setTimeout(function(){ - getCardNo(); - $("#sxModal").hide(); - customer_mamber_card_no = $("#paypar_account_no").val(); - if (customer_mamber_card_no == 0) { - customer_mamber_card_no = $("#membership_id").text() || 0; - } - if(sale_id != 0 && customer_mamber_card_no !=0){ - $.ajax({ - type: "POST", - url: "/origami/"+sale_id+"/send_account" , - data: { account_no : customer_mamber_card_no, amount : payment_amount, receipt_no : receipt_no}, - dataType: "json", - success: function(data) { - if (data.status == true) { - var valid_amount = parseFloat(data.old_balance_amount) - parseFloat(data.reload_amount); - $("#valid_amount").val((valid_amount > 0) ? parseFloat(valid_amount) : 0); + $("#sxModal").show(); + getCardNo(); + $("#sxModal").hide(); + customer_mamber_card_no = $("#paypar_account_no").val(); + if (customer_mamber_card_no == 0) { + customer_mamber_card_no = $("#membership_id").text() || 0; + } + if(sale_id != 0 && customer_mamber_card_no !=0){ + $.ajax({ + type: "POST", + url: "/origami/"+sale_id+"/send_account" , + data: { account_no : customer_mamber_card_no, amount : payment_amount, receipt_no : receipt_no}, + dataType: "json", + success: function(data) { + if (data.status == true) { + var valid_amount = parseFloat(data.old_balance_amount) - parseFloat(data.reload_amount); + $("#valid_amount").val((valid_amount > 0) ? parseFloat(valid_amount) : 0); - $.ajax({ - type: "POST", - url: "<%=origami_payment_paymal_path%>", - data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref,account_no:customer_mamber_card_no}, - success: function(result){ - if(result.status == true){ - swal({ - title: "Information!", - text: result.message, - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; - }); + $.ajax({ + type: "POST", + url: "<%=origami_payment_paymal_path%>", + data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref,account_no:customer_mamber_card_no}, + success: function(result){ + if(result.status == true){ + swal({ + title: "Information!", + text: result.message, + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; + }); - }else{ - swal ( "Opps",result.message ,"warning" ); - } + }else{ + swal ( "Opps",result.message ,"warning" ); + } + } + }); + }else{ + swal({ + title: 'Oops', + text: data.message.toString(), + type: 'error', + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment/others_payment/PAYMAL"; + }); } - }); - }else{ - swal({ - title: 'Oops', - text: data.message.toString(), - type: 'error', - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment/others_payment/PAYMAL"; - }); - } - } - }); - }else{ - swal("Opp","Please Check Member","warning") - } - },100); + } + }); + }else{ + swal("Opp","Please Check Member","warning") + } + }); // Read NFC card no from java @@ -326,6 +325,7 @@ // get CardNo from Java function setCardNo(cardNo){ + $("#sxModal").hide(); if(cardNo.length == 16){ $("#paypar_account_no").val(cardNo); } diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index 20bf09e2..ad2591c9 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -1119,32 +1119,30 @@ $(document).ready(function(){ $("#is_memberModal").hide(); $("#sxModal").show(); - setTimeout(function(){ - getCardNo(); - $("#sxModal").hide(); - customer_mamber_card_no = $("#paypar_account_no").val(); - - if(sale_id != 0 && customer_mamber_card_no != 0){ - $.ajax({ - type: "POST", - url: "/origami/"+sale_id+"/get_customer" , - data: { filter : customer_mamber_card_no ,type :"card"}, - dataType: "json", - success: function(data) { - if (data[0].customer_id == false) { - swal("Alert!", data[0].message, "error"); - }else{ - customer_id = data[0].customer_id; - customer_name = data[0].name; - membership_id = data[0].membership_id; - membership_type = data[0].membership_type; - update_sale(membership_id, customer_id, customer_name,sale_id); - } + getCardNo(); + $("#sxModal").hide(); + customer_mamber_card_no = $("#paypar_account_no").val(); + if(sale_id != 0 && customer_mamber_card_no != 0){ + $.ajax({ + type: "POST", + url: "/origami/"+sale_id+"/get_customer" , + data: { filter : customer_mamber_card_no ,type :"card"}, + dataType: "json", + success: function(data) { + if (data[0].customer_id == false) { + swal("Alert!", data[0].message, "error"); + }else{ + customer_id = data[0].customer_id; + customer_name = data[0].name; + membership_id = data[0].membership_id; + membership_type = data[0].membership_type; + update_sale(membership_id, customer_id, customer_name,sale_id); } - }); - } - },100); + + } + }); + } }); // Read NFC card no from java @@ -1156,6 +1154,7 @@ $(document).ready(function(){ // get CardNo from Java function setCardNo(cardNo){ + $("#sxModal").hide(); if(cardNo.length == 16){ $("#paypar_account_no").val(cardNo); } @@ -1530,85 +1529,83 @@ $(document).ready(function(){ $("#is_paymemberModal").hide(); $("#sxModal").show(); - setTimeout(function(){ - getCardNo(); - $("#sxModal").hide(); - customer_mamber_card_no = $("#paypar_account_no").val(); - if (customer_mamber_card_no == 0) { - customer_mamber_card_no = $("#membership_id").text() || 0; - } - if(sale_id != 0 && customer_mamber_card_no !=0){ - $.ajax({ - type: "POST", - url: "/origami/"+sale_id+"/send_account" , - data: { account_no : customer_mamber_card_no, amount : payment_amount, receipt_no : receipt_no}, - dataType: "json", - success: function(data) { - if (data.status == true) { - var valid_amount = parseFloat(data.old_balance_amount) - parseFloat(data.reload_amount); - // $("#valid_amount").val((valid_amount > 0) ? parseFloat(valid_amount) : 0); + getCardNo(); + $("#sxModal").hide(); + customer_mamber_card_no = $("#paypar_account_no").val(); + if (customer_mamber_card_no == 0) { + customer_mamber_card_no = $("#membership_id").text() || 0; + } + if(sale_id != 0 && customer_mamber_card_no !=0){ + $.ajax({ + type: "POST", + url: "/origami/"+sale_id+"/send_account" , + data: { account_no : customer_mamber_card_no, amount : payment_amount, receipt_no : receipt_no}, + dataType: "json", + success: function(data) { + if (data.status == true) { + var valid_amount = parseFloat(data.old_balance_amount) - parseFloat(data.reload_amount); + // $("#valid_amount").val((valid_amount > 0) ? parseFloat(valid_amount) : 0); - $.ajax({ - type: "POST", - url: "<%=origami_payment_paymal_path%>", - data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref,account_no:customer_mamber_card_no}, - success: function(result){ - if(result.status == true){ - swal({ - title: "Information!", - text: result.message, - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; - }); + $.ajax({ + type: "POST", + url: "<%=origami_payment_paymal_path%>", + data: {payment_amount:payment_amount,membership_id:0,sale_id:sale_id,transaction_ref:data.transaction_ref,account_no:customer_mamber_card_no}, + success: function(result){ + if(result.status == true){ + swal({ + title: "Information!", + text: result.message, + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id + "/"+cashier_type+"/payment"; + }); - }else{ - swal({ - title: 'Oops', - text: result.message, - type: 'warning', - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment"; - }); - } - } - }); - }else{ - swal({ - title: 'Oops', - text: data.message.toString(), - type: 'error', - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment"; - }); - } + }else{ + swal({ + title: 'Oops', + text: result.message, + type: 'warning', + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment"; + }); + } + } + }); + }else{ + swal({ + title: 'Oops', + text: data.message.toString(), + type: 'error', + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment"; + }); } - }); - }else{ - swal({ - title: 'Oops', - text: 'Please Check Member', - type: 'warning', - html: true, - closeOnConfirm: false, - closeOnCancel: false, - allowOutsideClick: false - }, function () { - window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment"; - }); - } - },100); + } + }); + }else{ + swal({ + title: 'Oops', + text: 'Please Check Member', + type: 'warning', + html: true, + closeOnConfirm: false, + closeOnCancel: false, + allowOutsideClick: false + }, function () { + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type + "/payment"; + }); + } }); // QR Code Reader From febb3986052e06fb9b9f93f9d44551160be525ca Mon Sep 17 00:00:00 2001 From: Thein Lin Kyaw Date: Sat, 5 Sep 2020 13:28:01 +0630 Subject: [PATCH 07/15] fix nfc add customer flow --- app/controllers/origami/home_controller.rb | 65 +++-- app/models/booking.rb | 6 +- app/views/crm/customers/_new_form.html.erb | 25 +- app/views/crm/customers/index.html.erb | 150 +++++------ app/views/origami/customers/index.html.erb | 286 ++++++++++----------- app/views/origami/dinga/index.html.erb | 155 ++++++----- app/views/origami/paymal/index.html.erb | 133 +++++----- app/views/origami/payments/show.html.erb | 226 ++++++++-------- 8 files changed, 513 insertions(+), 533 deletions(-) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index eaf3bab7..2f1cba36 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -30,49 +30,48 @@ class Origami::HomeController < BaseOrigamiController @status_order = "" @status_sale = "" - @sale_array = Array.new @shop = shop_detail @membership = MembershipSetting::MembershipSetting @payment_methods = PaymentMethodSetting.all - @order_items = Array.new - @dining.current_bookings.each do |booking| - if @obj_sale || @booking.blank? - @booking = booking - end + @sale_array = @dining.current_sales + if (booking = @dining.current_checkin_booking) + @booking = booking + @order_items = booking.order_items + @obj_order = booking.orders.first + end - if booking.sale_id - @sale_array.push(booking.sale) + if (booking = @dining.current_checkout_booking) + @booking = booking + @obj_sale = booking.sale + @sale_taxes = @obj_sale.sale_taxes + @status_sale = 'sale' + end - if @obj_sale.blank? - @obj_sale = booking.sale - @sale_taxes = @obj_sale.sale_taxes - @status_sale = 'sale' - end - else - @order_items += booking.order_items - @obj_order = booking.orders.first - end - - if @obj_sale || @customer.blank? - if obj = @obj_sale || @obj_order - @customer = obj.customer - @date = obj.created_at - end - end - - if @obj_sale - @status_order = 'sale' - else - @status_order = 'order' - end - - if (@obj_sale || @account_arr.blank?) && @customer - @account_arr = TaxProfile.find_by(id: @customer.tax_profiles) + if @obj_sale || @customer.blank? + if obj = @obj_sale || @obj_order + @customer = obj.customer + @date = obj.created_at end end + if @obj_sale + @status_order = 'sale' + else + @status_order = 'order' + end + + if (@obj_sale || @account_arr.blank?) && @customer + @account_arr = TaxProfile.find_by(id: @customer.tax_profiles) + end + + # @dining.current_bookings.each do |booking| + # if @obj_sale || @booking.blank? + # @booking = booking + # end + # end + #for bank integration @checkout_time = Lookup.collection_of('checkout_time') @checkout_alert_time = Lookup.collection_of('checkout_alert_time') diff --git a/app/models/booking.rb b/app/models/booking.rb index 276ef53e..760a3350 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -58,9 +58,9 @@ class Booking < ApplicationRecord end end - scope :active, -> {where("booking_status != 'moved'")} - scope :today, -> {where("created_at >= #{Time.now.utc}")} - scope :assign, -> { where(booking_status: 'assign')} + scope :active, -> { where('booking_status != ?', 'moved') } + scope :today, -> { where('created_at >= ?', Time.now) } + scope :assign, -> { where(booking_status: 'assign') } def self.sync_booking_records(bookings) if !bookings.nil? diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb index 7971ba72..b5bbc39c 100644 --- a/app/views/crm/customers/_new_form.html.erb +++ b/app/views/crm/customers/_new_form.html.erb @@ -57,7 +57,7 @@
    <%= f.input :name, :class => "form-control name", :required => true %> <% flash.each do |test, msg| %> - <% + <% str="[\"#{msg['name']}\"]" str.gsub!('["', '') str.gsub!('"]', '') %> @@ -94,7 +94,7 @@
    -
    +
    @@ -107,12 +107,12 @@ <% if f.object.image_path? %>

    <%= f.object.name %>

    <%= image_tag f.object.image_path.url, :class => "img-thumbnail" %> - <% else %> + <% else %> <%= image_tag "/image/menu_images/default.png", :class => "img-thumbnail" %> - <% end %> + <% end %>
    <%= f.file_field :image_path, :class => "img-thumbnail" %> - +
    @@ -160,7 +160,7 @@ <%end %> - +
    @@ -185,7 +185,7 @@
    -
    +
    @@ -201,7 +201,7 @@ <%end %> - +
    @@ -212,7 +212,7 @@ -
    +
    @@ -259,7 +259,7 @@ console.log(paypar_account_no); // Read Card Reader - $("#paypar_account_no").on('focus', function(e){ + $("#paypar_account_no").on('focus', function(e){ if($(this).val() == ''){ $("#sxModal").show(); getCardNo(); @@ -280,13 +280,13 @@ // get CardNo from Java function setCardNo(cardNo){ - $("#sxModal").hide(); check_member = localStorage.getItem("member_card"); if(cardNo.length == 16){ if(check_member == "true"){ $("#paypar_account_no").val(cardNo); $("#search").val(cardNo); $("#type").val("card"); + $("#filter_form").submit(); }else{ if($.inArray(cardNo, paypar_account_no) !== -1){ swal({ @@ -307,9 +307,10 @@ } } } + $("#sxModal").hide(); } $("#sxModal .btn_cancel").on('click',function(){ $("#sxModal").hide(); }); - \ No newline at end of file + diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index a5462b1d..a639631d 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -161,22 +161,13 @@ $(document).ready(function () { $("#oqs_loading_wrapper").show(); localStorage.setItem("member_card",false); - /*$('.datepicker').datepicker({ - format : 'dd-mm-yyyy', - autoclose: true - }); - $('.datepicker').attr('ReadOnly','true'); - $('.datepicker').css('cursor','pointer');*/ - // Read Card Reader $("#member_acc_no").on('click', function(e){ localStorage.setItem("member_card",true); - var cardNo = ""; $("#sxModal").show(); getCardNo(); }); - // QR Code Reader $("#qr_code").on('click', function(e){ var code = ""; @@ -236,88 +227,85 @@ /*customer UI tab btn*/ $(document).on('click',".customer_tr",function(){ - // if(this.checked){ - $(this).closest('tr').find('.checkbox_check').prop( "checked", true ); - //$( "#checkbox_check" ).prop( "checked", true ); - var sale_id = $("#sale_id").val() || 0; - var customer_id = $(this).attr('data-ref'); + // if(this.checked){ + $(this).closest('tr').find('.checkbox_check').prop( "checked", true ); + //$( "#checkbox_check" ).prop( "checked", true ); + var sale_id = $("#sale_id").val() || 0; + var customer_id = $(this).attr('data-ref'); - if(sale_id != 0){ - // var url = "/"+customer_id; - update_sale(customer_id,sale_id); - }else{ + if(sale_id != 0){ + // var url = "/"+customer_id; + update_sale(customer_id,sale_id); + }else{ - var url = "customers/" + customer_id + "/edit"; - } + var url = "customers/" + customer_id + "/edit"; + } - $("#customer_tax_profiles").children().removeAttr("selected").css({'color':'#000','background':'none'}); + $("#customer_tax_profiles").children().removeAttr("selected").css({'color':'#000','background':'none'}); - $.ajax({ - type: "GET", - url: url, - data: {}, - dataType: "json", - success: function(data) { - // Selected for Taxes - var taxes = JSON.stringify(data.tax_profiles); - var parse_taxes = JSON.parse(taxes); - $.each(parse_taxes, function(i, value){ - $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected").css({'color':'#fff','background':'#215d9c'}); - }); + $.ajax({ + type: "GET", + url: url, + data: {}, + dataType: "json", + success: function(data) { + // Selected for Taxes + var taxes = JSON.stringify(data.tax_profiles); + var parse_taxes = JSON.parse(taxes); + $.each(parse_taxes, function(i, value){ + $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected").css({'color':'#fff','background':'#215d9c'}); + }); - $('#customer_id').val(data.id); - $('#customer_name').val(data.name); - $('#customer_company').val(data.company); - $('#customer_contact_no').val(data.contact_no); - $('#customer_email').val(data.email); - $('#customer_salutation').val(data.salutation); - $('#customer_nrc_no').val(data.nrc_no); - $('#customer_card_no').val(data.card_no); - $('#customer_type').val(data.customer_type); - $('#paypar_account_no').val(data.paypar_account_no); - $('#customer_address').val(data.address); - $('#customer_date_of_birth').val(data.date_of_birth); - if(data.image_path.url!=undefined && data.image_path.url!=null){ - $('.menu-item-img .img-thumbnail').attr('src',data.image_path.url); - } - $('#customer_membership_type').val(data.membership_type); - $('.selectpicker > option[value="'+data.membership_type+'"]').attr('selected','selected'); - if (data.gender == 'Male') { - $('.male').prop( "checked", true ) - }else{ - $('.female').prop( "checked", true ) - } + $('#customer_id').val(data.id); + $('#customer_name').val(data.name); + $('#customer_company').val(data.company); + $('#customer_contact_no').val(data.contact_no); + $('#customer_email').val(data.email); + $('#customer_salutation').val(data.salutation); + $('#customer_nrc_no').val(data.nrc_no); + $('#customer_card_no').val(data.card_no); + $('#customer_type').val(data.customer_type); + $('#paypar_account_no').val(data.paypar_account_no); + $('#customer_address').val(data.address); + $('#customer_date_of_birth').val(data.date_of_birth); + if(data.image_path.url!=undefined && data.image_path.url!=null){ + $('.menu-item-img .img-thumbnail').attr('src',data.image_path.url); + } + $('#customer_membership_type').val(data.membership_type); + $('.selectpicker > option[value="'+data.membership_type+'"]').attr('selected','selected'); + if (data.gender == 'Male') { + $('.male').prop( "checked", true ) + }else{ + $('.female').prop( "checked", true ) + } - if(data.salutation == 'Mr') { - $('.mr').prop( "checked", true ) - }else if(data.salutation == 'Miss') { - $('.miss').prop( "checked", true ) - }else if(data.salutation == 'Mrs'){ - $('.mrs').prop( "checked", true ) - }else{ - $('.mdm').prop( "checked", true ) - } + if(data.salutation == 'Mr') { + $('.mr').prop( "checked", true ) + }else if(data.salutation == 'Miss') { + $('.miss').prop( "checked", true ) + }else if(data.salutation == 'Mrs'){ + $('.mrs').prop( "checked", true ) + }else{ + $('.mdm').prop( "checked", true ) + } - $('.membership_authentication_code').val(data.membership_authentication_code); + $('.membership_authentication_code').val(data.membership_authentication_code); - $('#update_customer').removeAttr('disabled').val(''); - $('#update_customer').attr('value', 'Update'); - $('#submit_customer').attr('disabled','disabled'); + $('#update_customer').removeAttr('disabled').val(''); + $('#update_customer').attr('value', 'Update'); + $('#submit_customer').attr('disabled','disabled'); - $("#new_customer").attr('class', 'simple_form edit_customer'); - var id = "edit_customer_"+customer_id; - $("#new_customer").attr('id', id); + $("#new_customer").attr('class', 'simple_form edit_customer'); + var id = "edit_customer_"+customer_id; + $("#new_customer").attr('id', id); - $(".edit_customer").attr('id', id); - $(".edit_customer").attr('action', '/crm/customers/' + $('#customer_id').val()); - $(".edit_customer").attr('action', '/crm/customers/' + $('#customer_id').val()); - $(".patch_method").html(''); - //$(".edit_customer").attr('method', 'PATCH'); - } - }); - // }else{ - - // } + $(".edit_customer").attr('id', id); + $(".edit_customer").attr('action', '/crm/customers/' + $('#customer_id').val()); + $(".edit_customer").attr('action', '/crm/customers/' + $('#customer_id').val()); + $(".patch_method").html(''); + //$(".edit_customer").attr('method', 'PATCH'); + } + }); }) function update_sale(customer_id,sale_id) { diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index fb804f5b..9144a260 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -82,7 +82,7 @@ - <% if crm_customer.customer_id != "" && crm_customer.customer_id != "" %> + <% if crm_customer.customer_id != "" && crm_customer.customer_id != "" %> <%= @i += 1 %> <%else%> - @@ -354,12 +354,12 @@ - + -
    +

    Card Tap

    - +
    @@ -368,6 +368,8 @@ var page = "<%= @page %>"; var paypar_account_no = []; $(function() { + setHeaderBreadCrumb(_CUSTOMERS_); + paypar_account_no = JSON.parse('<%= @paypar_accountno.to_json.html_safe %>', function (key, value) { var type; if (value && typeof value === 'object') { @@ -378,7 +380,7 @@ } return value; }); - console.log(paypar_account_no); + /* check webview loaded*/ var webview = <%= @webview %>; showHideNavbar(webview); @@ -400,47 +402,11 @@ } }); - $(document).ready(function () { - setHeaderBreadCrumb(_CUSTOMERS_); - - }); // Read Card Reader $("#member_acc_no").on('click', function(e){ localStorage.setItem("member_card",true); - var cardNo = ""; - var customer_id = ''; - var customer_name = ''; - var sale_id = $("#sale_id").val() || 0; - var customer_mamber_card_no = 0; $("#sxModal").show(); getCardNo(); - customer_mamber_card_no = $("#search").val(); - - if(sale_id != 0 && customer_mamber_card_no != 0){ - $.ajax({ - type: "POST", - url: "/origami/"+sale_id+"/get_customer" , - data: { filter : customer_mamber_card_no ,type :"card"}, - dataType: "json", - success: function(data) { - if (data[0].customer_id == false) { - swal("Alert!", data[0].message, "error"); - // $.alert({ - // title: 'Alert!', - // content: data[0].message, - // type: 'red', - // typeAnimated: true, - // btnClass: 'btn-danger', - // }); - }else{ - customer_id = data[0].customer_id; - customer_name = data[0].name; - update_sale(customer_id, customer_name,sale_id); - } - - } - }); - } }); /*new customer UI func:*/ @@ -449,7 +415,6 @@ //Wizard $('a[data-toggle="tab"]').on('show.bs.tab', function (e) { - var $target = $(e.target); if ($target.parent().hasClass('disabled')) { @@ -463,6 +428,7 @@ nextTab($active); $('.wizard .nav-tabs li.active .connecting-line').css({"border-bottom-left-radius": 0, "border-top-left-radius": 0}); }); + $(".prev-step").click(function (e) { var $active = $('.wizard .nav-tabs li a.active'); @@ -474,29 +440,30 @@ /*customer UI tab btn*/ function nextTab(elem) { - $(elem).parent().next().find('a[data-toggle="tab"]').click(); + $(elem).parent().next().find('a[data-toggle="tab"]').click(); } function prevTab(elem) { - $(elem).parent().prev().find('a[data-toggle="tab"]').click(); + $(elem).parent().prev().find('a[data-toggle="tab"]').click(); } /*customer UI tab btn*/ // Read NFC card no from java function getCardNo(){ - code2lab.readNFC(); + if (typeof code2lab != 'undefined') { + code2lab.readNFC(); + } } // get CardNo from Java function setCardNo(cardNo){ - $("#sxModal").hide(); check_member = localStorage.getItem("member_card"); if(cardNo.length == 16){ if(check_member == "true"){ $("#paypar_account_no").val(cardNo); $("#search").val(cardNo); $("#type").val("card"); - $("#filter_form").submit(); + get_customer(); }else{ if($.inArray(cardNo, paypar_account_no) !== -1){ swal({ @@ -517,47 +484,76 @@ } } } + $("#sxModal").hide(); + } + + function get_customer() { + var cardNo = ""; + var customer_id = ''; + var customer_name = ''; + var sale_id = $("#sale_id").val() || 0; + var customer_mamber_card_no = $("#search").val(); + + if(sale_id != 0 && customer_mamber_card_no != 0){ + $('#loading_wrapper').show(); + $.ajax({ + type: "POST", + url: "/origami/"+sale_id+"/get_customer" , + data: { filter : customer_mamber_card_no ,type :"card"}, + dataType: "json", + success: function(data) { + if (data[0].customer_id == false) { + swal("Alert!", data[0].message, "error"); + }else{ + customer_id = data[0].customer_id; + customer_name = data[0].name; + update_sale(customer_id, customer_name,sale_id); + } + $('#loading_wrapper').hide(); + } + }); + } } // QR Code Reader $("#qr_code").on('click', function(e){ - var code = ""; - var customer_id = ''; - var customer_name = ''; - var sale_id = $("#sale_id").val() || 0; - var customer_mamber_card_no = 0; + var code = ""; + var customer_id = ''; + var customer_name = ''; + var sale_id = $("#sale_id").val() || 0; + var customer_mamber_card_no = 0; - setTimeout(function(){ - code=getQRCode(); - setQRCode(code); - }, 100); + setTimeout(function(){ + code=getQRCode(); + setQRCode(code); + }, 100); - customer_mamber_card_no = $("#search").val(); + customer_mamber_card_no = $("#search").val(); - if(sale_id != 0 && customer_mamber_card_no != 0){ - $.ajax({ - type: "POST", - url: "/origami/"+sale_id+"/get_customer" , - data: { filter : customer_mamber_card_no ,type :"card"}, - dataType: "json", - success: function(data) { - if (data[0].customer_id == false) { - swal("Alert!", data[0].message, "error"); - // $.alert({ - // title: 'Alert!', - // content: data[0].message, - // type: 'red', - // typeAnimated: true, - // btnClass: 'btn-danger', - // }); - }else{ - customer_id = data[0].customer_id; - customer_name = data[0].name; - update_sale(customer_id, customer_name,sale_id); - } + if(sale_id != 0 && customer_mamber_card_no != 0){ + $.ajax({ + type: "POST", + url: "/origami/"+sale_id+"/get_customer" , + data: { filter : customer_mamber_card_no ,type :"card"}, + dataType: "json", + success: function(data) { + if (data[0].customer_id == false) { + swal("Alert!", data[0].message, "error"); + // $.alert({ + // title: 'Alert!', + // content: data[0].message, + // type: 'red', + // typeAnimated: true, + // btnClass: 'btn-danger', + // }); + }else{ + customer_id = data[0].customer_id; + customer_name = data[0].name; + update_sale(customer_id, customer_name,sale_id); } - }); - } + } + }); + } }); // Read qrcode from java @@ -572,81 +568,75 @@ } $(document).on('click',".customer_tr",function(){ - // if(this.checked){ - $(this).closest('tr').find('.checkbox_check').prop( "checked", true ); - var sale_id = $("#sale_id").val() || 0; - var customer_id = $(this).attr('data-ref'); - var customer_name = $(this).children("td:nth-child(3)").text(); - console.log(sale_id); - if(sale_id != 0){ - // var url = "/"+customer_id; - update_sale(customer_id, customer_name,sale_id); - }else{ + $(this).closest('tr').find('.checkbox_check').prop( "checked", true ); + var sale_id = $("#sale_id").val() || 0; + var customer_id = $(this).attr('data-ref'); + var customer_name = $(this).children("td:nth-child(3)").text(); - var url = "customers/"+customer_id; - } + if(sale_id != 0){ + update_sale(customer_id, customer_name,sale_id); + }else{ + var url = "customers/"+customer_id; + } - // Need To Clean? - $.ajax({ - type: "GET", - url: url, - data: {}, - dataType: "json", - success: function(data) { - var taxes = JSON.stringify(data.tax_profiles); - var parse_taxes = JSON.parse(taxes); - $.each(parse_taxes, function(i, value){ - $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected"); - }); + // Need To Clean? + $.ajax({ + type: "GET", + url: url, + data: {}, + dataType: "json", + success: function(data) { + var taxes = JSON.stringify(data.tax_profiles); + var parse_taxes = JSON.parse(taxes); + $.each(parse_taxes, function(i, value){ + $("#customer_tax_profiles option[value='" + value + "']").attr("selected","selected"); + }); - $('#customer_id').val(data.id); - $('#customer_name').val(data.name); - $('#customer_company').val(data.company); - $('#customer_contact_no').val(data.contact_no); - $('#customer_email').val(data.email); - $('#customer_date_of_birth').val(data.date_of_birth); - $('#customer_membership_type').val(data.membership_type); - $('.select > option[value="'+data.membership_id+'"]').attr('selected','selected'); - $('.membership_authentication_code').val(data.membership_authentication_code); - $('#customer_card_no').val(data.card_no); - $('#customer_type').val(data.customer_type); - $('#customer_salutation').val(data.salutation); - $('#customer_nrc_no').val(data.nrc_no); - $('#paypar_account_no').val(data.paypar_account_no); + $('#customer_id').val(data.id); + $('#customer_name').val(data.name); + $('#customer_company').val(data.company); + $('#customer_contact_no').val(data.contact_no); + $('#customer_email').val(data.email); + $('#customer_date_of_birth').val(data.date_of_birth); + $('#customer_membership_type').val(data.membership_type); + $('.select > option[value="'+data.membership_id+'"]').attr('selected','selected'); + $('.membership_authentication_code').val(data.membership_authentication_code); + $('#customer_card_no').val(data.card_no); + $('#customer_type').val(data.customer_type); + $('#customer_salutation').val(data.salutation); + $('#customer_nrc_no').val(data.nrc_no); + $('#paypar_account_no').val(data.paypar_account_no); - if (data.gender == 'Male') { - $('.male').prop( "checked", true ) - }else{ - $('.female').prop( "checked", true ) - } + if (data.gender == 'Male') { + $('.male').prop( "checked", true ) + }else{ + $('.female').prop( "checked", true ) + } - if (data.salutation == 'Mr') { - $('.mr').prop( "checked", true ) - } else if(data.salutation == 'Miss') { - $('.miss').prop( "checked", true ) - }else if(data.salutation == 'Mrs'){ - $('.mrs').prop( "checked", true ) - }else{ - $('.mdm').prop( "checked", true ) - } + if (data.salutation == 'Mr') { + $('.mr').prop( "checked", true ) + } else if(data.salutation == 'Miss') { + $('.miss').prop( "checked", true ) + }else if(data.salutation == 'Mrs'){ + $('.mrs').prop( "checked", true ) + }else{ + $('.mdm').prop( "checked", true ) + } - $('#update_customer').removeAttr('disabled').val(''); - $('#update_customer').attr('value', 'Update'); - // $('#submit_customer').attr('disabled','disabled'); + $('#update_customer').removeAttr('disabled').val(''); + $('#update_customer').attr('value', 'Update'); + // $('#submit_customer').attr('disabled','disabled'); - $("#new_customer").attr('class', 'simple_form edit_customer'); - var id = "edit_customer_"+$('#customer_id').val(); - $("#new_customer").attr('id', id); - $(".edit_customer").attr('action', '/crm/customers/' + $('#customer_id').val()); - $(".edit_customer").attr('action', '/crm/customers/' + $('#customer_id').val()); - $(".patch_method").append(''); - //$(".edit_customer").attr('method', 'PATCH'); - } - }); - // }else{ - - // } - }) + $("#new_customer").attr('class', 'simple_form edit_customer'); + var id = "edit_customer_"+$('#customer_id').val(); + $("#new_customer").attr('id', id); + $(".edit_customer").attr('action', '/crm/customers/' + $('#customer_id').val()); + $(".edit_customer").attr('action', '/crm/customers/' + $('#customer_id').val()); + $(".patch_method").append(''); + //$(".edit_customer").attr('method', 'PATCH'); + } + }); + }) function update_sale(customer_id, customer_name, sale_id) { var customer=""; diff --git a/app/views/origami/dinga/index.html.erb b/app/views/origami/dinga/index.html.erb index fbefb5be..6c04a15b 100644 --- a/app/views/origami/dinga/index.html.erb +++ b/app/views/origami/dinga/index.html.erb @@ -106,19 +106,14 @@
    -
    -

    Card Tap

    -
    - -
    -
    -
    -

    Card Tap

    -
    - -
    -
    + +
    +

    Card Tap

    +
    + +
    +
    @@ -145,10 +140,10 @@ - +