diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb
index f78f162a..0e7f3388 100644
--- a/app/controllers/origami/home_controller.rb
+++ b/app/controllers/origami/home_controller.rb
@@ -15,7 +15,7 @@ class Origami::HomeController < BaseOrigamiController
@rooms = Room.all.active.order('status desc')
@complete = Sale.where("sale_status != 'new'")
@orders = Order.all.order('date desc')
- @shop = Shop.find_by_id(1)
+
@status_order = ""
@status_sale = ""
@sale_array = Array.new
diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb
index 24d63b71..8c328030 100644
--- a/app/controllers/origami/payments_controller.rb
+++ b/app/controllers/origami/payments_controller.rb
@@ -166,7 +166,14 @@ class Origami::PaymentsController < BaseOrigamiController
def rounding_adj
saleObj = Sale.find(params[:sale_id])
- new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
+ @shop = Shop.find_by_id(1)
+
+ if @shop.is_rounding_adj
+ new_total = Sale.get_rounding_adjustment(saleObj.grand_total)
+ else
+ new_total = saleObj.grand_total
+ end
+
rounding_adj = new_total-saleObj.grand_total
saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj)
diff --git a/app/controllers/reports/credit_payment_controller.rb b/app/controllers/reports/credit_payment_controller.rb
new file mode 100644
index 00000000..dd9b3987
--- /dev/null
+++ b/app/controllers/reports/credit_payment_controller.rb
@@ -0,0 +1,61 @@
+class Reports::CreditPaymentController < BaseReportController
+authorize_resource :class => false
+ def index
+
+ from, to = get_date_range_from_params
+
+ @shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
+
+ @shift = ''
+ if params[:shift_name].to_i != 0
+ 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
+
+ @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at)
+ end
+ end
+
+ @sale_data = Sale.get_by_shift_sale_credit_payment(@shift_sale_range,@shift,from,to)
+
+ @from = from
+ @to = to
+
+ 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
+
+ def show
+ from, to = get_date_range_from_params
+
+ @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
+
+ date_arr = Array.new
+ @sale_data.each do |sale|
+ local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p")
+ local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p")
+ opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc
+ closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc
+ shift_id = sale.id.nil? ? '-' : sale.id
+ str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date}
+ date_arr.push(str)
+ end
+
+ out = {:status => 'ok', :message => date_arr}
+
+ respond_to do |format|
+ format.json { render json: out }
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/controllers/reports/void_sale_controller.rb b/app/controllers/reports/void_sale_controller.rb
new file mode 100644
index 00000000..80526ad0
--- /dev/null
+++ b/app/controllers/reports/void_sale_controller.rb
@@ -0,0 +1,60 @@
+class Reports::VoidSaleController < BaseReportController
+authorize_resource :class => false
+ def index
+
+ from, to = get_date_range_from_params
+
+ # @shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
+ @shift = ''
+ if params[:shift_name].to_i != 0
+ 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
+
+ @shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at)
+ end
+ end
+
+ @sale_data = Sale.get_void_sale(@shift,from,to)
+
+ @from = from
+ @to = to
+
+ 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
+
+ def show
+ from, to = get_date_range_from_params
+
+ @sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
+
+ date_arr = Array.new
+ @sale_data.each do |sale|
+ local_opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc.getlocal.strftime("%e %b %I:%M%p")
+ local_closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc.getlocal.strftime("%e %b %I:%M%p")
+ opening_date = sale.opening_date.nil? ? '-' : sale.opening_date.utc
+ closing_date = sale.closing_date.nil? ? '-' : sale.closing_date.utc
+ shift_id = sale.id.nil? ? '-' : sale.id
+ str = {:shift_id => shift_id, :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date}
+ date_arr.push(str)
+ end
+
+ out = {:status => 'ok', :message => date_arr}
+
+ respond_to do |format|
+ format.json { render json: out }
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 368aa424..bd3ce87e 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -68,7 +68,7 @@ class Ability
can :overall_void, :void
elsif user.role == "cashier"
-
+can :overall_void, :void
can :read, Order
can :update, Order
diff --git a/app/models/sale.rb b/app/models/sale.rb
index 197c7106..fc064b96 100644
--- a/app/models/sale.rb
+++ b/app/models/sale.rb
@@ -642,10 +642,36 @@ def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_ty
query = query.where("sale_status='completed' and sales.receipt_date between ? and ? #{payment_type} and sale_payments.payment_amount != 0",from,to)
.joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
.group("sales.sale_id")
- end
-
+ end
+end
+
+def self.get_by_shift_sale_credit_payment(shift_sale_range,shift,from,to)
+ query = SalePayment.select("s.receipt_no, sale_payments.*,s.receipt_date as sale_date,
+ s.cashier_name as cashier_name")
+ .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id")
+
+ if shift.present?
+ query = query.where("payment_method= 'creditnote' and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift.to_a)
+ elsif shift_sale_range.present?
+ query = query.where("payment_method='creditnote' and s.sale_status = 'completed' and s.shift_sale_id in (?)",shift_sale_range.to_a)
+ else
+ query = query.where("payment_method='creditnote' and s.sale_status = 'completed' and s.receipt_date between ? and ? ",from,to)
+ end
end
+ def self.get_void_sale(shift,from,to)
+ sale_arr = Array.new
+
+ account= Sale.select("sales.receipt_no,sales.receipt_date, sales.payment_status, sales.sale_status,sales.total_amount,sales.grand_total, sales.rounding_adjustment")
+ .joins("INNER JOIN shift_sales sh ON sh.id = sales.shift_sale_id")
+ .where("sales.sale_status = 'void' and (sh.shift_started_at between ? and ?
+ OR sh.shift_closed_at between ? and ? )", from ,to, from, to)
+
+ out = {:items => account}
+ sale_arr.push(out)
+ return sale_arr
+end
+
def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type)
if payment_type.blank?
@@ -680,18 +706,6 @@ def self.get_separate_tax(shift_sale_range=nil,shift,from,to,payment_type)
.group("sale_taxes.tax_name")
.order("sale_taxes.sale_tax_id asc")
end
-
- # query = SaleTax.select("SUM(tax_payable_amount) AS st_amount,tax_name")
- # .joins("INNER JOIN sales ON sales.sale_id = sale_taxes.sale_id")
- # .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
- # .group("sale_taxes.tax_name")
- # .order("sale_taxes.sale_tax_id asc")
-
- # if shift.present?
- # query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed'", shift.to_a)
- # else
- # query = query.where("sales.receipt_date between ? and ? #{payment_type} and sale_status= 'completed' ",from,to)
- # end
end
# def self.get_separate_tax(from,to,payment_method=nil)
diff --git a/app/views/origami/home/show.html.erb b/app/views/origami/home/show.html.erb
index 891524ec..206c8f20 100644
--- a/app/views/origami/home/show.html.erb
+++ b/app/views/origami/home/show.html.erb
@@ -20,7 +20,6 @@
-
@@ -452,9 +451,7 @@ $("#first_bill").on('click', function(){
$('#pay').on('click',function() {
var sale_id = $('#sale_id').val();
- var rounding_adj = $('#rounding_adj').val();
- if(rounding_adj == "true"){
var url = '/origami/sale/'+ sale_id + "/rounding_adj" ;
$.ajax({
type: "POST",
@@ -463,9 +460,7 @@ $('#pay').on('click',function() {
window.location.href = '/origami/sale/'+ sale_id + "/payment";
}
});
- }else{
- window.location.href = '/origami/sale/'+ sale_id + "/payment";
- }
+
});
diff --git a/app/views/reports/credit_payment/_shift_sale_report_filter.html.erb b/app/views/reports/credit_payment/_shift_sale_report_filter.html.erb
new file mode 100644
index 00000000..5313e61d
--- /dev/null
+++ b/app/views/reports/credit_payment/_shift_sale_report_filter.html.erb
@@ -0,0 +1,125 @@
+
+
+ <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %>
+ <% if period_type != false %>
+
+
+ Select Period
+
+ Select Period
+ Today
+ Yesterday
+ This week
+ Last week
+ Last 7 days
+ This month
+ Last month
+ Last 30 days
+ This year
+ Last year
+
+
+
+
+
+ From
+
+
+
+ To
+
+
+
+ All Shift
+
+
+
+
+
+
+
+ <% end %>
+
+ <% end %>
+
+
+
+
+
diff --git a/app/views/reports/credit_payment/index.html.erb b/app/views/reports/credit_payment/index.html.erb
new file mode 100644
index 00000000..6e3e6a58
--- /dev/null
+++ b/app/views/reports/credit_payment/index.html.erb
@@ -0,0 +1,150 @@
+
+
+
+ <%= render :partial=>'shift_sale_report_filter',
+ :locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_credit_payment_index_path} %>
+
+
+
+
+
+
+
+ <% unless @sale_data.blank? %>
+
+
+
+ <% if !params[:from].blank?%>
+
+ From Date : <%= params[:from] rescue '-'%> , To Date : <%= params[:to] rescue '-'%>
+
+ <% end %>
+
+ Shift Name
+ Receive No
+ Cashier Name
+ Customer Name
+ Credit Amount
+
+
+
+ <% @sale_data.each do |credit| %>
+
+
+ <% if @shift_from.nil? && @shift_to.nil? %>
+ <%= credit.sale_date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-'%>
+ <% else %>
+ <%= @shift_from rescue '-'%> - <%= @shift_to rescue '-'%>
+ <% end %>
+ <%= credit.receipt_no rescue '-' %>
+ <%= credit.cashier_name rescue '-' %>
+ <%= credit.sale.customer.name rescue '-' %>
+ <%= credit.payment_amount rescue '-' %>
+
+ <% end %>
+
+
+ <% end %>
+
+
+
+
\ No newline at end of file
diff --git a/app/views/reports/credit_payment/index.xls.erb b/app/views/reports/credit_payment/index.xls.erb
new file mode 100644
index 00000000..9597e3d9
--- /dev/null
+++ b/app/views/reports/credit_payment/index.xls.erb
@@ -0,0 +1,39 @@
+
+
+ <% unless @sale_data.blank? %>
+
+
+
+ <% if !params[:from].blank?%>
+
+ From Date : <%= params[:from] rescue '-'%> , To Date : <%= params[:to] rescue '-'%>
+
+ <% end %>
+
+ Shift Name
+ Receive No
+ Cashier Name
+ Customer Name
+ Credit Amount
+
+
+
+ <% @sale_data.each do |credit| %>
+
+
+ <% if @shift_from.nil? && @shift_to.nil? %>
+ <%= credit.sale_date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-'%>
+ <% else %>
+ <%= @shift_from rescue '-'%> - <%= @shift_to rescue '-'%>
+ <% end %>
+ <%= credit.receipt_no rescue '-' %>
+ <%= credit.cashier_name rescue '-' %>
+ <%= credit.sale.customer.name rescue '-' %>
+ <%= credit.payment_amount rescue '-' %>
+
+ <% end %>
+
+
+ <% end %>
+
+
\ No newline at end of file
diff --git a/app/views/reports/void_sale/_shift_sale_report_filter.html.erb b/app/views/reports/void_sale/_shift_sale_report_filter.html.erb
new file mode 100644
index 00000000..5313e61d
--- /dev/null
+++ b/app/views/reports/void_sale/_shift_sale_report_filter.html.erb
@@ -0,0 +1,125 @@
+
+
+ <%= form_tag report_path, :method => :get, :id=>"frm_report", :class => "form" do %>
+ <% if period_type != false %>
+
+
+ Select Period
+
+ Select Period
+ Today
+ Yesterday
+ This week
+ Last week
+ Last 7 days
+ This month
+ Last month
+ Last 30 days
+ This year
+ Last year
+
+
+
+
+
+ From
+
+
+
+ To
+
+
+
+ All Shift
+
+
+
+
+
+
+
+ <% end %>
+
+ <% end %>
+
+
+
+
+
diff --git a/app/views/reports/void_sale/index.html.erb b/app/views/reports/void_sale/index.html.erb
new file mode 100644
index 00000000..b008f5e8
--- /dev/null
+++ b/app/views/reports/void_sale/index.html.erb
@@ -0,0 +1,175 @@
+
+
+
+ <%= render :partial=>'shift_sale_report_filter',
+ :locals=>{ :period_type => true, :shift_name => true, :report_path =>reports_void_sale_index_path} %>
+
+
+
+
+
+
+
+ <% if @sale_data.count > 0 %>
+
+
+ <% if !params[:from].blank?%>
+
+ From Date : <%= params[:from] rescue '-'%> , To Date : <%= params[:to] rescue '-'%>
+
+ <% end %>
+ <% if @shift_from %>
+
+ <% if @shift.cashier_id %>
+ <% cashier_name = !@shift.nil? ? @shift.employee.name : '-' %>
+ <% end %>
+ Shift Name = <%= @shift_from rescue '-'%> - <%= @shift_to rescue '-'%> ( <%= cashier_name rescue '-'%> )
+
+ <% end %>
+
+ Receipt No
+ Sale Date
+ Total Amount
+ Grand Total
+ Rounding Adj.
+ Grand Total + Rounding Adj.
+ Sale Status
+ Remarks
+
+
+
+ <% total_amount = 0.0 %>
+ <% grand_total = 0.0 %>
+ <% rounding_adjustment = 0.0 %>
+ <% grand_rounding_adjustment = 0.0 %>
+ <% @sale_data.each do |result| %>
+ <% result[:items].each do |item| %>
+
+ <%= item.receipt_no rescue '-' %>
+ <%= item.date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-' %>
+ <%= item.total_amount.to_f rescue '-'%>
+ <%= item.grand_total.to_f rescue '-'%>
+ <%= item.rounding_adjustment.to_f rescue '-' %>
+ <%= item.grand_total.to_f + item.rounding_adjustment.to_f rescue '-'%>
+ <%= item.sales_status rescue '-' %>
+ <%= item.remarks rescue '-' %>
+
+ <% total_amount = total_amount.to_f + item.total_amount.to_f %>
+ <% grand_total = grand_total.to_f + item.grand_total.to_f %>
+ <% rounding_adjustment = rounding_adjustment.to_f + item.rounding_adjustment.to_f %>
+ <% grand_rounding_adjustment = grand_rounding_adjustment.to_f + item.grand_total.to_f + item.rounding_adjustment.to_f %>
+ <% end %>
+ <% end %>
+
+ Total Void Amount :
+ <%= total_amount rescue '-' %>
+ <%= grand_total rescue '-' %>
+ <%= rounding_adjustment rescue '-'%>
+ <%= grand_rounding_adjustment rescue '-'%>
+
+
+
+<% end %>
+
+
+
+
\ No newline at end of file
diff --git a/app/views/reports/void_sale/index.xls.erb b/app/views/reports/void_sale/index.xls.erb
new file mode 100644
index 00000000..9597e3d9
--- /dev/null
+++ b/app/views/reports/void_sale/index.xls.erb
@@ -0,0 +1,39 @@
+
+
+ <% unless @sale_data.blank? %>
+
+
+
+ <% if !params[:from].blank?%>
+
+ From Date : <%= params[:from] rescue '-'%> , To Date : <%= params[:to] rescue '-'%>
+
+ <% end %>
+
+ Shift Name
+ Receive No
+ Cashier Name
+ Customer Name
+ Credit Amount
+
+
+
+ <% @sale_data.each do |credit| %>
+
+
+ <% if @shift_from.nil? && @shift_to.nil? %>
+ <%= credit.sale_date.utc.getlocal.strftime("%e %b %I:%M%p") rescue '-'%>
+ <% else %>
+ <%= @shift_from rescue '-'%> - <%= @shift_to rescue '-'%>
+ <% end %>
+ <%= credit.receipt_no rescue '-' %>
+ <%= credit.cashier_name rescue '-' %>
+ <%= credit.sale.customer.name rescue '-' %>
+ <%= credit.payment_amount rescue '-' %>
+
+ <% end %>
+
+
+ <% end %>
+
+
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index d285cc2e..acb8b3f5 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -276,14 +276,10 @@ Rails.application.routes.draw do
resources :dailysale, :only => [:index, :show]
resources :saleitem, :only => [:index, :show]
resources :shiftsale, :only => [:index, :show]
+ resources :credit_payment, :only => [:index, :show]
+ resources :void_sale, :only => [:index, :show]
get "receipt_no/get_shift_by_date", to: "receipt_no#get_shift_by_date", as: "get_shift_by_date"
- # resources :sales, :only => [:index, :show]
- # resources :orders, :only => [:index, :show]
- # resources :customers, :only => [:index, :show]
- # resources :products, :only => [:index, :show]
- # resources :inventory, :only => [:index, :show]
- # resources :employees, :only => [:index, :show]
end
#mount_compendium at: '/report' #, controller: 'reports'