diff --git a/app/controllers/reports/card_sale_tran_controller.rb b/app/controllers/reports/card_sale_tran_controller.rb new file mode 100644 index 00000000..ff0b3231 --- /dev/null +++ b/app/controllers/reports/card_sale_tran_controller.rb @@ -0,0 +1,138 @@ +class Reports::CardSaleTranController < BaseReportController + authorize_resource :class => false + + # GET /transactions/sales + # GET /transactions/sales.json + def index + @payment_method = [["All Payments",''],["MPU Payment","mpu"], ["Visa Payment","visa"], + ["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"], + ["Alipay Payment","alipay"]] + @sales = Sale.all + # byebug + payment_type = params[:payment_type] + + # from = params[:from] + # to = params[:to] + from, to = get_date_range_from_params + status = 'Approved' + @shift_sale_range = '' + @shift = '' + + if params[:shift_name].to_i != 0 + + @shift_sale_range = CardSaleTran.get_by_shift_sale_by_card(from,to,status) + + @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 + + if from.nil? && to.nil? && payment_method.nil? && @shift.nil? + + @cardSales = CardSaleTran.where("status = 'Approved'").order("sale_id desc") + + @cardSales = Kaminari.paginate_array(@cardSales).page(params[:page]).per(20) + else + cardSale = CardSaleTran.searchReport(from,to,payment_type,@shift_sale_range,@shift) + if cardSale.count > 0 + @cardSales = cardSale + @cardSales = Kaminari.paginate_array(@cardSales).page(params[:page]).per(20) + else + @cardSales = 0 + end + end + + @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 + + # date range + PERIOD = { + "today" => 0, + "yesterday" => 1, + "this_week" => 2, + "last_week" => 3, + "last_7" => 4, + "this_month" => 5, + "last_month" => 6, + "last_30" => 7, + "this_year" => 8, + "last_year" => 9 + } + + def get_date_range_from_params + period_type = params[:period_type] + period = params[:period] + from = params[:from] + to = params[:to] + day_ref = Time.now.utc.getlocal + if from.present? && to.present? + f_date = DateTime.parse(from) + t_date = DateTime.parse(to) + f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) + t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) + from = f_time.beginning_of_day.utc.getlocal + to = t_time.end_of_day.utc.getlocal + else + case period.to_i + when PERIOD["today"] + from = day_ref.beginning_of_day.utc + to = day_ref.end_of_day.utc + + when PERIOD["yesterday"] + from = (day_ref - 1.day).beginning_of_day.utc + to = (day_ref - 1.day).end_of_day.utc + + when PERIOD["this_week"] + from = Time.now.beginning_of_week.utc + to = Time.now.utc + when PERIOD["last_week"] + from = (day_ref - 7.day).beginning_of_week.utc + to = (day_ref - 7.day).end_of_week.utc + when PERIOD["last_7"] + from = (day_ref - 7.day).utc + to = Time.now.utc + when PERIOD["this_month"] + from = Time.now.beginning_of_month.utc + to = Time.now.utc + when PERIOD["last_month"] + from = (day_ref - 1.month).beginning_of_month.utc + to = (day_ref - 1.month).end_of_month.utc + when PERIOD["last_30"] + from = (day_ref - 30.day).utc + to = Time.now.utc + when PERIOD["this_year"] + from = Time.now.beginning_of_year.utc + to = Time.now.utc + when PERIOD["last_year"] + from = (day_ref - 1.year).beginning_of_year.utc + to = (day_ref - 1.year).end_of_year.utc + end + end + + return from, to + end + +end diff --git a/app/controllers/transactions/card_sale_trans_controller.rb b/app/controllers/transactions/card_sale_trans_controller.rb new file mode 100644 index 00000000..b17fc608 --- /dev/null +++ b/app/controllers/transactions/card_sale_trans_controller.rb @@ -0,0 +1,105 @@ +class Transactions::CardSaleTransController < ApplicationController + authorize_resource :class => false + + # GET /transactions/sales + # GET /transactions/sales.json + def index + @status = [["All Status",''], ["Approved","Approved"], ["Declined","Declined"]] + @payment_method = [["All Payments",''],["MPU Payment","mpu"], ["Visa Payment","visa"], + ["Master Payment","master"], ["JCB Payment","jcb"],["UnionPay Payment","unionpay"], + ["Alipay Payment","alipay"]] + @sales = Sale.all + # byebug + payment_type = params[:payment_type] + sale_id = params[:sale_id] + status_type = params[:status_type] + + # from = params[:from] + # to = params[:to] + from, to = get_date_range_from_params + + if sale_id.nil? && from.nil? && to.nil? && payment_method.nil? && status_type.nil? + + @cardSales = CardSaleTran.where("status IS NOT NULL").order("sale_id desc") + + @cardSales = Kaminari.paginate_array(@cardSales).page(params[:page]).per(20) + else + cardSale = CardSaleTran.search(sale_id,from,to,payment_type,status_type) + if cardSale.count > 0 + @cardSales = cardSale + @cardSales = Kaminari.paginate_array(@cardSales).page(params[:page]).per(20) + else + @cardSales = 0 + end + end + + end + + # date range + PERIOD = { + "today" => 0, + "yesterday" => 1, + "this_week" => 2, + "last_week" => 3, + "last_7" => 4, + "this_month" => 5, + "last_month" => 6, + "last_30" => 7, + "this_year" => 8, + "last_year" => 9 + } + + def get_date_range_from_params + period_type = params[:period_type] + period = params[:period] + from = params[:from] + to = params[:to] + day_ref = Time.now.utc.getlocal + if from.present? && to.present? + f_date = DateTime.parse(from) + t_date = DateTime.parse(to) + f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) + t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) + from = f_time.beginning_of_day.utc.getlocal + to = t_time.end_of_day.utc.getlocal + else + case period.to_i + when PERIOD["today"] + from = day_ref.beginning_of_day.utc + to = day_ref.end_of_day.utc + + when PERIOD["yesterday"] + from = (day_ref - 1.day).beginning_of_day.utc + to = (day_ref - 1.day).end_of_day.utc + + when PERIOD["this_week"] + from = Time.now.beginning_of_week.utc + to = Time.now.utc + when PERIOD["last_week"] + from = (day_ref - 7.day).beginning_of_week.utc + to = (day_ref - 7.day).end_of_week.utc + when PERIOD["last_7"] + from = (day_ref - 7.day).utc + to = Time.now.utc + when PERIOD["this_month"] + from = Time.now.beginning_of_month.utc + to = Time.now.utc + when PERIOD["last_month"] + from = (day_ref - 1.month).beginning_of_month.utc + to = (day_ref - 1.month).end_of_month.utc + when PERIOD["last_30"] + from = (day_ref - 30.day).utc + to = Time.now.utc + when PERIOD["this_year"] + from = Time.now.beginning_of_year.utc + to = Time.now.utc + when PERIOD["last_year"] + from = (day_ref - 1.year).beginning_of_year.utc + to = (day_ref - 1.year).end_of_year.utc + end + end + + return from, to + end + +end diff --git a/app/models/card_sale_tran.rb b/app/models/card_sale_tran.rb index 7c496b56..0aef0952 100644 --- a/app/models/card_sale_tran.rb +++ b/app/models/card_sale_tran.rb @@ -1,2 +1,84 @@ class CardSaleTran < ApplicationRecord -end + + belongs_to :sale + + def self.search(filter,from,to,payment_type,status_type) + if filter.blank? + keyword = '' + else + keyword = " s.cashier_name LIKE ? OR c.name LIKE ? OR s.sale_id LIKE ?","%#{filter}%","%#{filter}%","%#{filter}%" + end + + if payment_type.blank? + payment = '' + else + if payment_type == 'unionpay' + payment = " app LIKE 'cup'" + else + payment = " app LIKE '#{payment_type}'" + end + end + + if status_type.blank? + status = '' + else + status = " status = '#{status_type}'" + end + + if from.present? && to.present? + + # cardSale = CardSaleTran.where("DATE_FORMAT(req_date,'%Y-%m-%d') >= ?" + " AND DATE_FORMAT(req_date,'%Y-%m-%d') <= ? and status IS NULL ", from,to) + from_date = from.strftime("%Y-%m-%d") + to_date = to.strftime("%Y-%m-%d") + query = CardSaleTran.joins("Join sales s ON s.sale_id = card_sale_trans.sale_id"+ + " JOIN customers c ON c.customer_id = s.customer_id") + cardSale = query.where("req_date >= ? and req_date <= ? and status is not null",from_date,to_date) + query1 = cardSale.where(keyword) + query2 = query1.where(payment) + query3 = query2.where(status) + + end + end + + def self.searchReport(from,to,payment_type,shift_sale_range,shift) + + if payment_type.blank? + payment = '' + else + if payment_type == 'unionpay' + payment = " app LIKE 'cup'" + else + payment = " app LIKE '#{payment_type}'" + end + end + + if from.present? && to.present? + + # cardSale = CardSaleTran.where("DATE_FORMAT(req_date,'%Y-%m-%d') >= ?" + " AND DATE_FORMAT(req_date,'%Y-%m-%d') <= ? and status IS NULL ", from,to) + from_date = from.strftime("%Y-%m-%d") + to_date = to.strftime("%Y-%m-%d") + query = CardSaleTran.joins("Join sales s ON s.sale_id = card_sale_trans.sale_id"+ + " JOIN customers c ON c.customer_id = s.customer_id") + cardSale = query.where("req_date >= ? and req_date <= ? and status = 'Approved'",from_date,to_date) + + if shift.present? + query1 = cardSale.where("s.shift_sale_id in (?)", shift.to_a) + elsif shift_sale_range.present? + query1 = cardSale.where("s.shift_sale_id in (?)",shift_sale_range.to_a) + else + query1 = cardSale.where("s.receipt_date between ? and ?",from,to) + end + query2 = query1.where(payment) + + end + end + + def self.get_by_shift_sale_by_card(from,to,status) + query = ShiftSale.select("shift_sales.id ,shift_started_at AS opening_date, + shift_closed_at As closing_date,") + .order("shift_sales.id DESC") + return query = query.where("shift_sales.shift_started_at >= ?" , from) + byebug + end + +end \ No newline at end of file diff --git a/app/models/sale.rb b/app/models/sale.rb index ccd25fc5..e504bb3d 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -6,6 +6,7 @@ class Sale < ApplicationRecord #before_create :generate_receipt_no belongs_to :cashier, :optional => true belongs_to :customer, :optional => true + belongs_to :employees has_many :sale_items has_many :sale_discount_items has_many :sale_discounts diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index a4340f0e..4052ed56 100644 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -123,6 +123,16 @@ <%= t("views.right_panel.detail.order_reservation") %> <% end %> + <% if can? :menage, Sale %> +
  • + <%= t :cb_payments %> +
  • + <% end %> + <% if can? :menage, Sale %> +
  • + <%= t :cb_settlement %> +
  • + <% end %> <% if can? :index, :dailysale %> @@ -174,6 +184,9 @@
  • Stock Check
  • +
  • + CB Payments +
  • <%end%> diff --git a/app/views/reports/card_sale_tran/_shift_card_sale_tran_report_filter.html.erb b/app/views/reports/card_sale_tran/_shift_card_sale_tran_report_filter.html.erb new file mode 100644 index 00000000..0d70fe4f --- /dev/null +++ b/app/views/reports/card_sale_tran/_shift_card_sale_tran_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? @payment_method %> +
    + + <%= select_tag "payment_type", options_for_select(@payment_method, :selected => params[:payment_type]), :class => "form-control" %> +
    + <% end %> +
    + + +
    + <% if not defined? payments %> + +
    + + + +
    + <% end %> +
    + + + +
    +
    + + +
    +
    + + +
    +
    +
    + +
    +
    + <% end %> + + <% end %> +
    + + diff --git a/app/views/reports/card_sale_tran/index.html.erb b/app/views/reports/card_sale_tran/index.html.erb new file mode 100644 index 00000000..673da3ae --- /dev/null +++ b/app/views/reports/card_sale_tran/index.html.erb @@ -0,0 +1,186 @@ + +
    +
    + + <%= render :partial=>'shift_card_sale_tran_report_filter', + :locals=>{ :period_type => true, :shift_name => true,:payments => true, :report_path =>reports_card_sale_tran_index_path} %> +
    + + + +
    +
    + + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + + + + + + <% if @cardSales != 0 %> + <% @cardSales.each do |cardSale| %> + + + + + + + + + + + + + + <% end %> + <% else %> + + <% 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.req_date") %><%= t("views.right_panel.detail.req_no") %><%= t("views.right_panel.detail.req_amount") %><%= t("views.right_panel.detail.res_date") %><%= t("views.right_panel.detail.ref_no") %><%= t("views.right_panel.detail.res_amount") %><%= t("views.right_panel.detail.payment_type") %><%= t("views.right_panel.detail.Customer_name") %><%= t("views.right_panel.detail.Cashier_name") %><%= t("views.right_panel.detail.detail") %><%= t("views.right_panel.detail.status") %>
    <%= cardSale.req_date %> <%= cardSale.req_time.utc.getlocal.strftime("%I:%M %p") %><%= cardSale.req_inv_no %><%= cardSale.req_amt %><%= cardSale.res_date %> <%= cardSale.res_time.utc.getlocal.strftime("%I:%M %p") %><%= cardSale.ref_no %><%= cardSale.res_amt %><%= cardSale.app %><%= cardSale.sale.customer.name rescue '-' %><%= cardSale.sale.cashier_name rescue '-' %>TID : <%= cardSale.terminal_id %> +
    + MID : <%= cardSale.trace %> +
    + Batch : <%= cardSale.batch_no %> +
    + Trace : <%= cardSale.merchant_id %> +
    <%= cardSale.status %>

    There is no data for search....

    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/app/views/reports/card_sale_tran/index.xls.erb b/app/views/reports/card_sale_tran/index.xls.erb new file mode 100644 index 00000000..145dce33 --- /dev/null +++ b/app/views/reports/card_sale_tran/index.xls.erb @@ -0,0 +1,74 @@ + + + + + + + +
    +
    +
    +
    + + + + + + <% if @shift_from %> + + <% if @shift_data.employee %> + <% cashier_name = !@shift_data.nil? ? @shift_data.employee.name : '-' %> + <% end %> + + + <% end %> + + + + + + + + + + + + + + + + + <% if @cardSales != 0 %> + <% @cardSales.each do |cardSale| %> + + + + + + + + + + + + + + <% end %> + <% else %> + + <% end %> + +
    <%= t("views.right_panel.detail.from_date") %> : <%= @from.utc.getlocal.strftime("%Y-%b-%d") rescue '-' %> - <%= t("views.right_panel.detail.to_date") %> : <%= @to ? @to.utc.getlocal.strftime("%Y-%b-%d") : '-'%>
    <%= t("views.right_panel.detail.shift_name") %> = <%= @shift_from %> - <%= @shift_to %> ( <%= cashier_name %> )
    <%= t("views.right_panel.detail.req_date") %><%= t("views.right_panel.detail.req_no") %><%= t("views.right_panel.detail.req_amount") %><%= t("views.right_panel.detail.res_date") %><%= t("views.right_panel.detail.ref_no") %><%= t("views.right_panel.detail.res_amount") %><%= t("views.right_panel.detail.payment_type") %><%= t("views.right_panel.detail.Customer_name") %><%= t("views.right_panel.detail.Cashier_name") %><%= t("views.right_panel.detail.detail") %><%= t("views.right_panel.detail.status") %>
    <%= cardSale.req_date %> <%= cardSale.req_time.utc.getlocal.strftime("%I:%M %p") %><%= cardSale.req_inv_no %><%= cardSale.req_amt %><%= cardSale.res_date %> <%= cardSale.res_time.utc.getlocal.strftime("%I:%M %p") %><%= cardSale.ref_no %><%= cardSale.res_amt %><%= cardSale.app %><%= cardSale.sale.customer.name rescue '-' %><%= cardSale.sale.cashier_name rescue '-' %>TID : <%= cardSale.terminal_id %> +
    + MID : <%= cardSale.trace %> +
    + Batch : <%= cardSale.batch_no %> +
    + Trace : <%= cardSale.merchant_id %> +
    <%= cardSale.status %>

    There is no data for search....

    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb b/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb index 1d7c2a94..6cf8ce02 100755 --- a/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb +++ b/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb @@ -18,7 +18,7 @@ - <% if defined? payments %> + <% if not defined? payments %>
    @@ -47,7 +47,7 @@
    -
    +

    diff --git a/app/views/transactions/card_sale_trans/index.html.erb b/app/views/transactions/card_sale_trans/index.html.erb new file mode 100644 index 00000000..a3d2a88a --- /dev/null +++ b/app/views/transactions/card_sale_trans/index.html.erb @@ -0,0 +1,211 @@ + +
    +
    +
    +
    + + + + + + + + + +
    + <%= form_tag transactions_card_sale_trans_path, :method => :get do %> +
    +
    + + +
    + + <% if defined? @payment_method %> +
    + + <%= select_tag "payment_type", options_for_select(@payment_method, :selected => params[:payment_type]), :class => "form-control" %> +
    + <% end %> + + <% if not defined? status %> + +
    + + + +
    + <% end %> +
    + + +
    +
    + + +
    + +
    + +
    +
    +
    + <% end %> +
    + +
    +
    +
    + + + + + + + + + + + + + + + + + + + + <% if @cardSales != 0 %> + <% @cardSales.each do |cardSale| %> + + + + + + + + + + + + + + + + <% end %> + <% else %> + + <% end %> + +
    <%= t("views.right_panel.detail.sale_id") %><%= t("views.right_panel.detail.req_date") %><%= t("views.right_panel.detail.req_no") %><%= t("views.right_panel.detail.req_amount") %><%= t("views.right_panel.detail.res_date") %><%= t("views.right_panel.detail.ref_no") %><%= t("views.right_panel.detail.res_amount") %><%= t("views.right_panel.detail.payment_type") %><%= t("views.right_panel.detail.Customer_name") %><%= t("views.right_panel.detail.Cashier_name") %><%= t("views.right_panel.detail.detail") %><%= t("views.right_panel.detail.status") %>
    <%= link_to cardSale.sale_id, transactions_sale_path(cardSale.sale_id) rescue '-' %><%= cardSale.req_date %> <%= cardSale.req_time.utc.getlocal.strftime("%I:%M %p") %><%= cardSale.req_inv_no %><%= cardSale.req_amt %><%= cardSale.res_date %> <%= cardSale.res_time.utc.getlocal.strftime("%I:%M %p") %><%= cardSale.ref_no %><%= cardSale.res_amt %><%= cardSale.app %><%= cardSale.sale.customer.name rescue '-' %><%= cardSale.sale.cashier_name rescue '-' %>TID : <%= cardSale.terminal_id %> +
    + MID : <%= cardSale.trace %> +
    + Batch : <%= cardSale.batch_no %> +
    + Trace : <%= cardSale.merchant_id %> +
    <%= cardSale.status %>

    There is no data for search....

    +
    + <% if @cardSales != 0 %> + <%= paginate @cardSales %> + <% end %> +
    +
    +
    + +
    +
    + + + + + + + + + diff --git a/app/views/transactions/card_sale_trans/show.json.jbuilder b/app/views/transactions/card_sale_trans/show.json.jbuilder new file mode 100644 index 00000000..48c70528 --- /dev/null +++ b/app/views/transactions/card_sale_trans/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "transactions_sales/transactions_sale", transactions_sale: @transactions_sale diff --git a/config/initializers/action_controller.rb b/config/initializers/action_controller.rb index fb212f13..04204a73 100644 --- a/config/initializers/action_controller.rb +++ b/config/initializers/action_controller.rb @@ -18,13 +18,13 @@ class ActionController::Base # redirect_to root_url(:host => request.domain) + "store_error" render :json => [{ status: false, message: 'Invalid Access!'}] end - else - # check for license file - if check_license - current_license(ENV["SX_PROVISION_URL"]) - else - redirect_to activate_path - end + # else + # # check for license file + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end end end diff --git a/config/routes.rb b/config/routes.rb index cb5f742b..5fee5f28 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -464,6 +464,7 @@ scope "(:locale)", locale: /en|mm/ do resources :shift_sales resources :surveys resources :order_reservations + resources :card_sale_trans get "/sales/:sale_id/manual_complete_sale" => "manual_sales#manual_complete_sale", :as => "manual_complete_sale" get "/sales/:sale_id/void" => "manual_sales#void", :as => "void" @@ -487,6 +488,7 @@ scope "(:locale)", locale: /en|mm/ do resources :product_sale, :only => [:index, :show] resources :order_reservation, :only => [:index, :show] resources :induty, :only => [:index, :show] + resources :card_sale_tran get "saleitem/get_shift_by_date", to: "saleitem#show", as: "get_shift_by_sale_item" get "receipt_no/get_shift_by_date", to: "receipt_no#get_shift_by_date", as: "get_shift_by_date"