From 1d08954a76c1b699cf1ad768fd39b2a65176b0ec Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Fri, 30 Jun 2017 13:32:56 +0630 Subject: [PATCH] update shift sale --- .../javascripts/reports/shiftsale.coffee | 3 + app/assets/stylesheets/reports/shiftsale.scss | 3 + .../origami/payments_controller.rb | 5 + .../reports/shiftsale_controller.rb | 18 ++ app/helpers/reports/shiftsale_helper.rb | 2 + app/models/ability.rb | 1 + app/models/sale.rb | 43 ++++- app/views/layouts/_header.html.erb | 1 + .../_shift_sale_report_filter.html.erb | 127 ++++++++++++++ app/views/reports/shiftsale/index.html.erb | 160 ++++++++++++++++++ .../index.xls.erb} | 78 +-------- config/routes.rb | 1 + .../reports/shiftsale_controller_spec.rb | 5 + spec/helpers/reports/shiftsale_helper_spec.rb | 15 ++ 14 files changed, 384 insertions(+), 78 deletions(-) create mode 100644 app/assets/javascripts/reports/shiftsale.coffee create mode 100644 app/assets/stylesheets/reports/shiftsale.scss create mode 100644 app/controllers/reports/shiftsale_controller.rb create mode 100644 app/helpers/reports/shiftsale_helper.rb create mode 100644 app/views/reports/shiftsale/_shift_sale_report_filter.html.erb create mode 100644 app/views/reports/shiftsale/index.html.erb rename app/views/reports/{daily_sale/index.html.erb => shiftsale/index.xls.erb} (79%) create mode 100644 spec/controllers/reports/shiftsale_controller_spec.rb create mode 100644 spec/helpers/reports/shiftsale_helper_spec.rb diff --git a/app/assets/javascripts/reports/shiftsale.coffee b/app/assets/javascripts/reports/shiftsale.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/reports/shiftsale.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/reports/shiftsale.scss b/app/assets/stylesheets/reports/shiftsale.scss new file mode 100644 index 00000000..0e0a4c32 --- /dev/null +++ b/app/assets/stylesheets/reports/shiftsale.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the reports/shiftsale controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 1d26438e..0d2d9082 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -9,7 +9,12 @@ class Origami::PaymentsController < BaseOrigamiController sale_data = Sale.find_by_sale_id(sale_id) sale_items = SaleItem.where("sale_id=?",sale_id) + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + rounding_adj = sale_data.grand_total - new_total + + sale_data.update_attributes(grand_total: new_total,rounding_adjustment:rounding_adj) # Print for First Bill to Customer + unique_code = "ReceiptBillPdf" #shop detail shop_details = Shop.find(1) diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb new file mode 100644 index 00000000..5f13857d --- /dev/null +++ b/app/controllers/reports/shiftsale_controller.rb @@ -0,0 +1,18 @@ +class Reports::ShiftsaleController < ApplicationController + # authorize_resource :class => false + + def index + + from, to, report_type = get_date_range_from_params + @sale_data = Sale.get_by_shiftsales(from,to) + respond_to do |format| + format.html + format.xls + end + end + + def show + + end +end + diff --git a/app/helpers/reports/shiftsale_helper.rb b/app/helpers/reports/shiftsale_helper.rb new file mode 100644 index 00000000..967a8c6b --- /dev/null +++ b/app/helpers/reports/shiftsale_helper.rb @@ -0,0 +1,2 @@ +module Reports::ShiftsaleHelper +end diff --git a/app/models/ability.rb b/app/models/ability.rb index 90ff2f52..c591fba8 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -45,6 +45,7 @@ class Ability can :remove_discount_items, :discount can :remove_all_discount, :discount + can :first_bill, :payment can :show, :payment can :create, :payment can :reprint, :payment diff --git a/app/models/sale.rb b/app/models/sale.rb index bf3bc216..9c3aea00 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -322,6 +322,41 @@ class Sale < ApplicationRecord end end + def self.get_rounding_adjustment(num) + ## 0 -- 25 -- 50 -- 75 -- 100 + # if get_rounded_amt == true + value = 0 + + num = num.to_f.round + get_last_no = num.to_s.last(2).to_f + if get_last_no.between?(0,25) + ## down to 0 + num -= get_last_no + else + if get_last_no.between?(26,50) + ## up to 50 + value = 50 - get_last_no.to_f + num += value + puts 'up to 50' + else + if get_last_no.between?(51, 75) + ## down to 50 + value = get_last_no.to_f - 50 + num -= value + puts 'down to 50' + else + ## up to 100 + value = 100 - get_last_no.to_f + num += value + puts 'up to 100' + end + end + end + # end + return num + end + + def self.daily_sales_list(from,to) payments_total = Sale.select("CAST((CONVERT_TZ(sales.receipt_date,'+00:00','+06:30')) AS DATE) as sale_date, SUM(case when (sale_payments.payment_method='mpu') then sale_payments.payment_amount else 0 end) as mpu_amount, @@ -387,13 +422,13 @@ def self.get_by_range_by_saleitems(from,to,status,report_type) .group('mi.id') .order("mi.menu_category_id") - query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id + query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code" + " JOIN menu_categories mc ON mc.id = mi.menu_category_id JOIN employees ea ON ea.id = sales.cashier_id") - query = query.where("receipt_date between ? and ? and sale_status=?",from,to,status) + query = query.where("receipt_date between ? and ? and sale_status=?",from,to,status) @@ -409,6 +444,10 @@ def self.get_by_range_by_saleitems(from,to,status,report_type) end +def self.get_by_shiftsales(from,to) + return ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to) +end + private def generate_custom_id diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index 345ca63f..558d35dd 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -42,6 +42,7 @@
  • <%= link_to "Daily Sale Report", reports_dailysale_index_path, :tabindex =>"-1" %>
  • <%= link_to "Sales Item Report", reports_saleitem_index_path, :tabindex =>"-1" %>
  • <%= link_to "Receipt Report", reports_receipt_no_index_path, :tabindex =>"-1" %>
  • + diff --git a/app/views/reports/shiftsale/_shift_sale_report_filter.html.erb b/app/views/reports/shiftsale/_shift_sale_report_filter.html.erb new file mode 100644 index 00000000..34173d99 --- /dev/null +++ b/app/views/reports/shiftsale/_shift_sale_report_filter.html.erb @@ -0,0 +1,127 @@ +
    +
    + <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %> + <% if period_type != false %> +
    +
    + + +
    + + +
    + + + +
    +
    + + +
    +
    + +
    +
    + <% end %> + + <% end %> +
    +
    + + \ No newline at end of file diff --git a/app/views/reports/shiftsale/index.html.erb b/app/views/reports/shiftsale/index.html.erb new file mode 100644 index 00000000..8582a578 --- /dev/null +++ b/app/views/reports/shiftsale/index.html.erb @@ -0,0 +1,160 @@ + + +
    + <%= render :partial=>'shift_sale_report_filter', + :locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_shiftsale_index_path} %> +
    +
    + +
    +
    + +
    +
    + +
    + +
    +
    + + + <% if params[:from]%> + + + + <% end %> + + + + + + + + + + + + + + + + + <% void = 0%> + <% cash = 0%> + <% credit = 0%> + <% accept_credit = 0%> + <% foc = 0%> + <% card = 0%> + <% total = 0%> + <% rounding_adj = 0%> + <% g_total = 0 %> + + <% @sale_data.each do |result| %> + + + + + + + + + + + + <% grand_total = result[:grand_total].to_f - result[:rounding_adj].to_f %> + + + <% void += result[:void_amount].to_f %> + <% cash += result[:cash_amount].to_f %> + <% credit += result[:credit_amount].to_f %> + <% accept_credit += result[:accept_credit_amount].to_f %> + <% foc += result[:foc_amount].to_f %> + <% card += result[:card_amount].to_f %> + <% total += result[:grand_total].to_f %> + <% rounding_adj += result[:rounding_adj].to_f %> + <% g_total += grand_total.to_f %> + + <% end %> + + + + + + + + + + + + + + +
    From Date : <%= params[:from] rescue '-'%> ,To Date : <%= params[:to] rescue '-'%>
    Cashier StationShift NameVoid AmountCash PaymentCredit ChargesCredit PaymentFOC PaymentCard PaymentGrand Total + +
    Rounding Adj
    Rounding AdjGrand Total
    + <%= result[:cashier_station_name] rescue '-'%> + <%= result[:shift_started_at].strftime("%e %b %I:%M%p") rescue '-' %> - + <%= result[:shift_closed_at].strftime("%e %b %I:%M%p") rescue '-' %> + <%= sprintf "%.2f",result[:cash_amount].to_f.to_d rescue '-'%><%= sprintf "%.2f",result[:credit_amount].to_f.to_d rescue '-'%><%= sprintf "%.2f",result[:accept_credit_amount].to_f.to_d rescue '-'%><%= sprintf "%.2f",result[:foc_amount].to_f.to_d rescue '-'%><%= sprintf "%.2f",result[:card_amount].to_f.to_d rescue '-'%><%= sprintf "%.2f",result[:grand_total].to_f.to_d rescue '-'%><%= sprintf "%.2f",result[:rounding_adj].to_f.to_d rescue '-'%><%= sprintf "%.2f",grand_total.to_f.to_d rescue '-'%>
    (<%= sprintf("%.2f",void) rescue '-'%>)<%= sprintf("%.2f",cash) rescue '-'%><%= sprintf("%.2f",credit) rescue '-'%><%= sprintf("%.2f",accept_credit) rescue '-'%><%= sprintf("%.2f",foc) rescue '-'%><%= sprintf("%.2f",card) rescue '-'%><%= sprintf("%.2f",total) rescue '-'%><%= sprintf("%.2f",rounding_adj) rescue '-'%><%= sprintf("%.2f",g_total) rescue '-'%>
    +
    +
    +
    + + + \ No newline at end of file diff --git a/app/views/reports/daily_sale/index.html.erb b/app/views/reports/shiftsale/index.xls.erb similarity index 79% rename from app/views/reports/daily_sale/index.html.erb rename to app/views/reports/shiftsale/index.xls.erb index 7b790148..67e76e3c 100644 --- a/app/views/reports/daily_sale/index.html.erb +++ b/app/views/reports/shiftsale/index.xls.erb @@ -1,26 +1,4 @@ - - -
    - <%= render :partial=>'shift_sale_report_filter', - :locals=>{ :period_type => true, :shift_name => false, :report_path =>reports_daily_sales_path} %> -
    -
    - -
    -
    - -
    -
    - -
    -
    +
    @@ -135,56 +113,4 @@ <% end %>
    -
    -
    - - - \ No newline at end of file +
    \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 37033f22..e3a0d7a0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -264,6 +264,7 @@ Rails.application.routes.draw do resources :receipt_no, :only => [:index, :show] resources :dailysale, :only => [:index, :show] resources :saleitem, :only => [:index, :show] + resources :shiftsale, :only => [:index, :show] # resources :sales, :only => [:index, :show] # resources :orders, :only => [:index, :show] # resources :customers, :only => [:index, :show] diff --git a/spec/controllers/reports/shiftsale_controller_spec.rb b/spec/controllers/reports/shiftsale_controller_spec.rb new file mode 100644 index 00000000..ed90f941 --- /dev/null +++ b/spec/controllers/reports/shiftsale_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Reports::ShiftsaleController, type: :controller do + +end diff --git a/spec/helpers/reports/shiftsale_helper_spec.rb b/spec/helpers/reports/shiftsale_helper_spec.rb new file mode 100644 index 00000000..3555ce0c --- /dev/null +++ b/spec/helpers/reports/shiftsale_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Reports::ShiftsaleHelper. For example: +# +# describe Reports::ShiftsaleHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Reports::ShiftsaleHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end