diff --git a/app/assets/images/ajax-loader.gif b/app/assets/images/ajax-loader.gif
new file mode 100644
index 00000000..4155add2
Binary files /dev/null and b/app/assets/images/ajax-loader.gif differ
diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss
index a7b25b7a..f8a768a9 100644
--- a/app/assets/stylesheets/origami.scss
+++ b/app/assets/stylesheets/origami.scss
@@ -213,3 +213,29 @@ tr.discount-item-row:hover {
margin-left:-40px !important;
margin-top:-40px !important;
}
+
+/*Loading gif for payment*/
+
+#loading_wrapper{
+
+ position: fixed;
+ background-color: #C8C8C8 ;
+ height: 100%;
+ width: 100%;
+ left: 0;
+ opacity: 0.6;
+ top: 0;
+ z-index: 9999999;
+}
+#loading{
+ position: relative;
+ height: 100%;
+ width: 100%;
+ background-image: url('../../../image/loading-ajax.gif');
+ background-position: center center;
+ background-repeat: no-repeat;
+ opacity: 1;
+ filter: alpha(opacity=100); /* ie */
+ -moz-opacity: 1; /* mozilla */
+
+}
\ No newline at end of file
diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb
index 12eeccd2..af9ec4fc 100644
--- a/app/controllers/base_report_controller.rb
+++ b/app/controllers/base_report_controller.rb
@@ -34,12 +34,10 @@ class BaseReportController < ActionController::Base
to = params[:to]
day_ref = Time.now.utc.getlocal
- if params[:report_type] == "daily_sale" || params[:report_type] == "sale_item"
+ if from.present? && to.present?
- if from != "" && to != ""
-
- f_date = DateTime.parse(params[:from])
- t_date = DateTime.parse(params[:to])
+ 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
@@ -83,59 +81,6 @@ class BaseReportController < ActionController::Base
to = (day_ref - 1.year).end_of_year.utc
end
end
- else # end daily sale report
- if period_type.to_i == 1
-
- if params[:from] != "" && params[:to] !=""
-
- f_date = DateTime.parse(params[:from])
- t_date = DateTime.parse(params[: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
- from = day_ref.beginning_of_day.utc
- to = day_ref.end_of_day.utc
- end
- 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
- end
return from, to
diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb
index 7b846db0..bbfdb912 100644
--- a/app/controllers/crm/customers_controller.rb
+++ b/app/controllers/crm/customers_controller.rb
@@ -49,21 +49,7 @@ class Crm::CustomersController < BaseCrmController
#get customer amount
@customer = Customer.find(params[:id])
@response = Customer.get_membership_transactions(@customer)
- # get member information
- total = Customer.get_member_account(@customer)
-
-
- @balance = 0.00
- @accountable_type = ''
- if total["status"]==true
- total["data"].each do |res|
- if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount"
- @balance += res["balance"]
- # @accountable_type = res["accountable_type"]
- @accountable_type = "Rebate Balance"
- end
- end
- end
+
# @response = ""
#end customer amount
diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb
index e0596166..f7e1c63a 100644
--- a/app/controllers/origami/discounts_controller.rb
+++ b/app/controllers/origami/discounts_controller.rb
@@ -7,7 +7,7 @@ class Origami::DiscountsController < BaseOrigamiController
if Sale.exists?(sale_id)
@sale_data = Sale.find(sale_id)
end
-
+ @member_discount = MembershipSetting.find_by_discount(1)
@accounts = Account.all
end
@@ -167,33 +167,39 @@ class Origami::DiscountsController < BaseOrigamiController
'Accept' => 'application/json'
}, :timeout => 10)
rescue HTTParty::Error
- response = {status: false, message: "Can't open membership server "}
+ response = {:status=> false, :message => "Can't open membership server " }
rescue Net::OpenTimeout
-
- response = { status: false , message: "Can't open membership server "}
-
+ response = {:status=> false, :message => "Can't open membership server " }
rescue OpenURI::HTTPError
- response = { status: false, message: "Can't open membership server "}
+ response = {:status=> false, :message => "Can't open membership server " }
rescue SocketError
- response = { status: false, message: "Can't open membership server "}
+ response = {:status=> false, :message => "Can't open membership server " }
end
-
- puts "ssssssssss"
- puts response.to_json
table_id = sale.bookings[0].dining_facility_id
table_type = DiningFacility.find(table_id).type
-
+ puts response
+ puts "sssssssssss"
# Re-calc All Amount in Sale
if response["status"] == true
- sale.compute_by_sale_items(sale_id, sale.sale_items, response["discount_earned"])
- end
- result = {:status=> "Success", :table_id => table_id,:table_type => table_type }
- # if response["status"] == false
- # result = {:status=> "Success", :table_id => table_id,:table_type => table_type,:url_status => response[:status],:url_message => response[:message] }
- # end
+ discount_amount = response["discount_earned"]
+ if response["discount_bonus_earned"]
+ discount_amount = discount_amount + response["discount_bonus_earned"]
+ end
+ sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount')
+ result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type }
+ end
+
+ if response["status"] == "500"
+ result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type }
+ end
+ if !response.nil?
+ if response[:status] == false
+ result = {:status=> response[:message],:title=>"Alert", :table_id => table_id,:table_type => table_type }
+ end
+ end
render :json => result.to_json
end
diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb
index 32f4ab12..7ee03e47 100644
--- a/app/controllers/origami/home_controller.rb
+++ b/app/controllers/origami/home_controller.rb
@@ -4,7 +4,7 @@ class Origami::HomeController < BaseOrigamiController
def index
@tables = Table.all.active.order('status desc')
@rooms = Room.all.active.order('status desc')
- @complete = Sale.all
+ @complete = Sale.where("sale_status != 'new'")
@orders = Order.all.order('date desc')
# @shift = ShiftSale.current_open_shift(current_user.id)
end
@@ -13,7 +13,7 @@ class Origami::HomeController < BaseOrigamiController
def show
@tables = Table.all.active.order('status desc')
@rooms = Room.all.active.order('status desc')
- @complete = Sale.all
+ @complete = Sale.where("sale_status != 'new'")
@orders = Order.all.order('date desc')
@status_order = ""
@status_sale = ""
diff --git a/app/controllers/origami/orders_controller.rb b/app/controllers/origami/orders_controller.rb
index ef213ddd..f3cddd74 100644
--- a/app/controllers/origami/orders_controller.rb
+++ b/app/controllers/origami/orders_controller.rb
@@ -3,7 +3,7 @@ class Origami::OrdersController < BaseOrigamiController
def show
@tables = Table.all.active.order('status desc')
@rooms = Room.all.active.order('status desc')
- @complete = Sale.all
+ @complete = Sale.where("sale_status != 'new'")
@orders = Order.all.order('status desc')
@order = Order.find(params[:order_id])
sale_order = SaleOrder.find_by_order_id(@order.order_id)
diff --git a/app/controllers/origami/others_payments_controller.rb b/app/controllers/origami/others_payments_controller.rb
index c050c3f3..2a24e2ac 100644
--- a/app/controllers/origami/others_payments_controller.rb
+++ b/app/controllers/origami/others_payments_controller.rb
@@ -6,6 +6,8 @@ class Origami::OthersPaymentsController < BaseOrigamiController
@sale_id = params[:sale_id]
@payment_method_setting = PaymentMethodSetting.all
+ @rebate = MembershipSetting.find_by_rebate(1)
+
# @sale_id = params[:sale_id]
# sale_data = Sale.find_by_sale_id(@sale_id)
diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb
index f2919cce..24d63b71 100644
--- a/app/controllers/origami/payments_controller.rb
+++ b/app/controllers/origami/payments_controller.rb
@@ -18,7 +18,8 @@ class Origami::PaymentsController < BaseOrigamiController
# customer= Customer.where('customer_id=' +.customer_id)
customer= Customer.find(sale_data.customer_id)
# get member information
- if customer.membership_id != nil
+ rebate = MembershipSetting.find_by_rebate(1)
+ if customer.membership_id != nil && rebate
member_info = Customer.get_member_account(customer)
end
# get printer info
@@ -55,7 +56,8 @@ class Origami::PaymentsController < BaseOrigamiController
#shop detail
shop_details = Shop.find(1)
# get member information
- if customer.membership_id != nil
+ rebate = MembershipSetting.find_by_rebate(1)
+ if customer.membership_id != nil && rebate
member_info = Customer.get_member_account(customer)
rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
end
@@ -89,9 +91,9 @@ class Origami::PaymentsController < BaseOrigamiController
#get customer amount
@customer = Customer.find(@sale_data.customer_id)
-
+ rebate = MembershipSetting.find_by_rebate(1)
# get member information
- if @customer.membership_id != nil
+ if @customer.membership_id != nil && rebate
response = Customer.get_member_account(@customer)
if response["status"]==true
response["data"].each do |res|
@@ -145,7 +147,8 @@ class Origami::PaymentsController < BaseOrigamiController
#shop detail
shop_details = Shop.find(1)
# get member information
- if customer.membership_id != nil
+ rebate = MembershipSetting.find_by_rebate(1)
+ if customer.membership_id != nil && rebate
member_info = Customer.get_member_account(customer)
rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no)
end
diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb
index e5728f99..823136b9 100644
--- a/app/controllers/origami/rooms_controller.rb
+++ b/app/controllers/origami/rooms_controller.rb
@@ -3,7 +3,7 @@ class Origami::RoomsController < BaseOrigamiController
def show
@tables = Table.all.active.order('status desc')
@rooms = Room.all.active.order('status desc')
- @complete = Sale.all
+ @complete = Sale.where("sale_status != 'new'")
@orders = Order.all.order('date desc')
@room = DiningFacility.find(params[:room_id])
@sale_array = Array.new
@@ -31,9 +31,6 @@ class Origami::RoomsController < BaseOrigamiController
end
end
end
- puts "hhhhhhhhhh"
- puts @status
- puts @obj.to_json
end
diff --git a/app/controllers/origami/sales_controller.rb b/app/controllers/origami/sales_controller.rb
index c397da0f..3a9586fb 100644
--- a/app/controllers/origami/sales_controller.rb
+++ b/app/controllers/origami/sales_controller.rb
@@ -3,7 +3,7 @@ class Origami::SalesController < BaseOrigamiController
def show
@tables = Table.all.active.order('status desc')
@rooms = Room.all.active.order('status desc')
- @complete = Sale.all
+ @complete = Sale.where("sale_status != 'new'")
@orders = Order.all.order('date desc')
@sale = Sale.find(params[:sale_id])
end
diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb
index 1f085ac8..e227d81a 100644
--- a/app/controllers/origami/shifts_controller.rb
+++ b/app/controllers/origami/shifts_controller.rb
@@ -4,8 +4,6 @@ class Origami::ShiftsController < BaseOrigamiController
end
def show
- puts ">>>>>"
- puts current_user.id
@shift = ShiftSale.current_open_shift(current_user.id)
end
diff --git a/app/controllers/reports/receipt_no_controller.rb b/app/controllers/reports/receipt_no_controller.rb
index e71df43e..d1427e6e 100644
--- a/app/controllers/reports/receipt_no_controller.rb
+++ b/app/controllers/reports/receipt_no_controller.rb
@@ -1,25 +1,31 @@
class Reports::ReceiptNoController < BaseReportController
authorize_resource :class => false
def index
- from, to, report_type = get_date_range_from_params
+ @payments = [["All Payment",''], ["Cash Payment","cash"], ["Credit Payment","creditnote"], ["FOC Payment","foc"], ["Other Payment","card"]]
- if params[:shift_name].to_i != 0
- @shift = ShiftSale.where('shift_started_at >= ? and shift_closed_at <= ?',from,to).take
- # puts @shift.to_json
- if @shift.present?
- @sale_data = Sale.where('shift_sale_id = ? ',@shift.id)
- @sale_taxes = Sale.get_separate_tax(from,to)
- end
- else
- @sale_data = Sale.where("sale_status=? and receipt_date between ? and ?","completed",from.utc,to.utc)
- @sale_taxes = Sale.get_separate_tax(from.utc,to.utc)
- end
-
+ from, to = get_date_range_from_params
- if @shift.present?
- @shift_from = @shift.shift_started_at.nil? ? '-' : @shift.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p")
- @shift_to = @shift.shift_closed_at.nil? ? '-' : @shift.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p")
- end
+ @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_shift_sales_by_receipt_no(@shift_sale_range,@shift,from,to, params[:payment_type])
+
+ 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
@@ -28,7 +34,7 @@ authorize_resource :class => false
end
def show
- from, to, report_type = get_date_range_from_params
+ from, to = get_date_range_from_params
@sale_data = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
@@ -38,7 +44,8 @@ authorize_resource :class => false
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
- str = { :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date}
+ 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
@@ -48,205 +55,4 @@ authorize_resource :class => false
format.json { render json: out }
end
end
-
-
- def get_date_range_from_params
-
- period_type = params[:period_type]
- period = params[:period]
-
- branch = params[:branch]
- report_type = params[:report_type]
-
- shift_name = params[:shift_name]
- unless shift_name.nil?
- shift_arr = shift_name.split(' - ')
- shift_from = shift_arr[0]
- shift_to = shift_arr[1]
- end
-
- day_ref = day_ref = Time.now.utc.getlocal
-
- if period_type.to_i == 1
-
- ### =>search by from and to
- unless shift_name.nil?
- if shift_name.to_s == '0'
- ### => all shift
- f_date = DateTime.parse(params[:from])
- t_date = DateTime.parse(params[: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
- unless shift_from == '-'
- f_date = DateTime.parse(shift_from)
- from = f_date
- else
- from = ''
- end
-
- unless shift_to == '-'
- t_date = DateTime.parse(shift_to)
- to = t_date
- else
- to = ''
- end
- end
- else
- f_date = DateTime.parse(params[:from])
- t_date = DateTime.parse(params[: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
- end
- else
- ### => search by Today or yesterday
-
- unless shift_name.nil?
- if shift_name.to_s == '0'
- ### => all shift
- 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
-
- else
- unless shift_from == '-'
- f_date = DateTime.parse(shift_from)
- #f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
- from = f_date.utc
- else
- from = ''
- end
-
- unless shift_to == '-'
- t_date = DateTime.parse(shift_to)
- #t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
- to = t_date.utc
- else
- to = ''
- end
- end
- else
- if params[:report_type].to_i != 0
- r_type = params[:report_type].to_s
-
- if r_type == 'shift_item'
-
- 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
- else
- ### => report not shift
- 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
- end
-
- end
-
- return from, to,report_type
- end
-
-
end
\ No newline at end of file
diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb
index 80bd8b93..b9f71494 100644
--- a/app/controllers/reports/saleitem_controller.rb
+++ b/app/controllers/reports/saleitem_controller.rb
@@ -2,17 +2,20 @@ class Reports::SaleitemController < BaseReportController
authorize_resource :class => false
def index
- from, to, report_type = get_date_range_from_params
+ from, to = get_date_range_from_params
shift_sale_range = Sale.get_by_shift_sale(from,to,Sale::SALE_STATUS_COMPLETED)
shift = ''
- if to.blank?
- shift = ShiftSale.where('shift_started_at = ? and shift_closed_at is NULL ',from)
- else
- shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',from, to)
- end
+ 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
- @sale_data, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED, report_type)
+ shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at)
+ end
+ end
+ @sale_data, @discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED)
@account_cate_count = Hash.new {|hash, key| hash[key] = 0}
@@ -27,7 +30,7 @@ class Reports::SaleitemController < BaseReportController
@sale_data.each {|acc| @totalByAccount[acc.account_id] += acc.grand_total}
- if !shift.nil?
+ 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")
@@ -52,7 +55,8 @@ class Reports::SaleitemController < BaseReportController
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
- str = { :local_opening_date => local_opening_date, :local_closing_date => local_closing_date, :opening_date => opening_date, :closing_date => closing_date}
+ 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
@@ -62,226 +66,5 @@ class Reports::SaleitemController < BaseReportController
format.json { render json: out }
end
end
-
- def get_date_range_from_params
- period_type = params[:period_type]
- period = params[:period]
- from = params[:from]
- to = params[:to]
- branch = params[:branch]
- report_type = params[:report_type]
-
- shift_name = params[:shift_name]
- unless shift_name.nil?
- shift_arr = shift_name.split(' - ')
- shift_from = shift_arr[0]
- shift_to = shift_arr[1]
- end
-
- day_ref = Time.now
-
- if period_type.to_i == 1
- ### =>search by from and to
- unless shift_name.nil?
- if shift_name.to_s == '0'
- ### => all shift
- #f_date = DateTime.parse(from)
- #t_date = DateTime.parse(to)
- if params[:from] && params[:to]
- if params[:from] != "" && params[:to] !=""
- f_date = DateTime.strptime(from, "%m/%d/%Y")
- t_date = DateTime.strptime(to, "%m/%d/%Y")
-
- 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
- to = t_time.end_of_day.utc
- end
- else
- from = day_ref.beginning_of_day.utc
- to = day_ref.end_of_day.utc
- end
- else
- unless shift_from == '-'
- f_date = DateTime.parse(shift_from)
- from = f_date
- else
- from = ''
- end
-
- unless shift_to == '-'
- t_date = DateTime.parse(shift_to)
- to = t_date
- else
- to = ''
- end
- end
- else
- # f_date = DateTime.parse(from)
- # t_date = DateTime.parse(to)
- if params[:from] && params[:to]
- if params[:from] != "" && params[:to] !=""
- f_date = DateTime.strptime(from, "%m/%d/%Y")
- t_date = DateTime.strptime(to, "%m/%d/%Y")
- 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
- to = t_time.end_of_day.utc
- end
- else
- from = day_ref.beginning_of_day.utc
- to = day_ref.end_of_day.utc
- end
- end
- else
- ### => search by Today or yesterday
- unless shift_name.nil?
- if shift_name.to_s == '0'
- ### => all shift
- 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
-
- else
- unless shift_from == '-'
- f_date = DateTime.parse(shift_from)
- # f_date = DateTime.strptime(shift_from, "%m/%d/%Y")
- #f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec)
- from = f_date
- else
- from = ''
- end
-
- unless shift_to == '-'
- t_date = DateTime.parse(shift_to)
- # t_date = DateTime.strptime(shift_to, "%m/%d/%Y")
-
- #t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec)
- to = t_date
- else
- to = ''
- end
- end
- else
- if params[:report_type].to_i != 0
- r_type = params[:report_type].to_s
-
- if r_type == 'shift_item'
-
- 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
- else
- ### => report not shift
- 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
- end
-
-
-
- end
-
- return from, to,report_type
- end
-
+
end
diff --git a/app/controllers/reports/shiftsale_controller.rb b/app/controllers/reports/shiftsale_controller.rb
index 87fae97d..fc3adbf9 100644
--- a/app/controllers/reports/shiftsale_controller.rb
+++ b/app/controllers/reports/shiftsale_controller.rb
@@ -3,16 +3,40 @@ class Reports::ShiftsaleController < BaseReportController
def index
- from, to, report_type = get_date_range_from_params
- @sale_data = Sale.get_by_shiftsales(from,to)
- respond_to do |format|
+ from, to = get_date_range_from_params
+ @shift = ''
+ if params[:shift_name].to_i != 0
+ @shift = ShiftSale.find(params[:shift_name])
+ end
+ @sale_data = Sale.get_by_shiftsales(from,to,@shift)
+
+ 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
diff --git a/app/controllers/settings/membership_settings_controller.rb b/app/controllers/settings/membership_settings_controller.rb
index 36bb0092..d4da84cd 100644
--- a/app/controllers/settings/membership_settings_controller.rb
+++ b/app/controllers/settings/membership_settings_controller.rb
@@ -70,6 +70,6 @@ class Settings::MembershipSettingsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def settings_membership_setting_params
- params.require(:membership_setting).permit(:membership_type, :is_active, :gateway_communication_type, :gateway_url, :auth_token, :merchant_account_id, :created_by)
+ params.require(:membership_setting).permit(:membership_type, :is_active,:discount,:rebate,:bonus,:point, :gateway_communication_type, :gateway_url, :auth_token, :merchant_account_id, :created_by)
end
end
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 1cf1d902..f9d98bfc 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -75,8 +75,8 @@ class Ability
can :read, Sale
can :update, Sale
- can :add_customer, Customer
- can :update_sale_by_customer, Customer
+ can :add_customer, Customer
+ can :update_sale_by_customer, Customer
can :index, :other_charge
can :create, :other_charge
diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb
index 39858c65..71ad42c8 100644
--- a/app/models/menu_category.rb
+++ b/app/models/menu_category.rb
@@ -1,12 +1,12 @@
class MenuCategory < ApplicationRecord
- # before_create :generate_menu_category_code
+ before_create :generate_menu_category_code
belongs_to :menu
has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id"
belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true
has_many :menu_items
- validates_presence_of :name, :menu, :code, :order_by
+ validates_presence_of :name, :menu, :order_by
default_scope { order('order_by asc') }
diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb
index 9dd9e741..1f1afbe4 100644
--- a/app/models/menu_item.rb
+++ b/app/models/menu_item.rb
@@ -1,6 +1,6 @@
class MenuItem < ApplicationRecord
- # before_create :generate_menu_item_code
+ before_create :generate_menu_item_code
belongs_to :menu_category, :optional => true
has_many :menu_item_instances
@@ -8,7 +8,7 @@ class MenuItem < ApplicationRecord
has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id"
belongs_to :account
- validates_presence_of :item_code, :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item
+ validates_presence_of :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item
default_scope { order('item_code asc') }
diff --git a/app/models/menu_item_instance.rb b/app/models/menu_item_instance.rb
index ab4c806d..f39c29a2 100644
--- a/app/models/menu_item_instance.rb
+++ b/app/models/menu_item_instance.rb
@@ -1,6 +1,6 @@
class MenuItemInstance < ApplicationRecord
belongs_to :menu_item
- # before_create :generate_menu_item_instance_code
+ before_create :generate_menu_item_instance_code
def self.findParentCategory(item)
if item.menu_category_id
diff --git a/app/models/sale.rb b/app/models/sale.rb
index 12896b7d..4e47f6cd 100644
--- a/app/models/sale.rb
+++ b/app/models/sale.rb
@@ -503,84 +503,18 @@ def self.get_by_range_by_saleitems(from,to,status,report_type)
- case report_type.to_i
- when REPORT_TYPE["daily"]
- return query
- when REPORT_TYPE["monthly"]
-
- return query.group("MONTH(date)")
- when REPORT_TYPE["yearly"]
- return query.group("YEAR(date)")
- end
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)
+def self.get_by_shiftsales(from,to,shift)
+ if !shift.blank?
+ ShiftSale.where("id =?",shift.id)
+ else
+ ShiftSale.where("(shift_started_at between ? and ? OR shift_closed_at between ? and ? )", from, to, from, to)
+ end
end
-# def self.get_by_shiftsales(from,to)
-# shift_sales = ShiftSale.select('shift_sales.id, cs.name as cashier_station_name, shift_sales.shift_started_at as opening_date, shift_sales.shift_closeed_at as closing_date')
-# .joins(" INNER JOIN cashier_terminals cs ON cs.id = shift_sales.cashier_terminal_id")
-# .where("shift_sales.employee_id = ? and (shift_sales.shift_started_at between ? and ? OR shift_sales.shift_closeed_at between ? and ? )", employee, from, to, from, to)
-# .order("shift_sales.id DESC")
-
-# sale_arr = Array.new
-# shift_sales.each do |shift|
-# all_total= Sale.select("grand_total,sr.payment_method, sr.payment_amount, rounding_adjustment")
-# .joins("join employees e on sales.cashier_id = e.id join shift_sales sh on sh.id = sales.shift_sale_id")
-# .joins("INNER JOIN (select * from sale_payments group by sale_payments.sale_id, sale_payments.payment_method) sr ON sr.sale_id = sales.sale_id")
-# .where("sales.shift_sale_id =? and sales.sale_status = 'completed' and sales.total_amount != 0",shift.id)
-
-# void = Sale.select("SUM(sales.grand_total) AS grand_total")
-# .joins("join shift_sales sh on sh.id = sales.shift_sale_id")
-# .where('sales.sale_status = "void" and sales.total_amount != 0 and sales.shift_sale_id = ?', shift.id)
-# .sum(:grand_total)
-# cash = all_total.select('sr.payment_method')
-# .where('sr.payment_method = "cash"')
-# .sum(:amount)
-
-# credit = all_total.where('sr.payment_method = "creditnote"')
-# .sum(:amount)
-
-# accept_credit = all_total.select('ci.amout')
-# .joins("INNER JOIN credit_items ci ON ci.sale_id = sales.id")
-# .where('sr.payment_method = "creditnote"')
-# .sum(:amout)
-
-
-
-# foc = all_total.where('sales.payment_method = "foc" and sales.sale_status = "completed"')
-# .sum(:grand_total)
-
-# card = all_total.select('payment_method')
-# .where('sr.payment_method = "card"')
-# .sum(:amount).to_f
-
-# rounding_adj = all_total.sum(:rounding_adjustment)
-
-# discount = all_total.sum(:discount_amount)
-# void = void.nil? ? 0 : void
-# cash = cash.nil? ? 0 : cash
-# credit = credit.nil? ? 0 : credit
-# foc = foc.nil? ? 0 : foc
-# card = card.nil? ? 0 : card
-# accept_credit = accept_credit.nil? ? 0 : accept_credit
-# # all_payments = void.to_d + cash.to_d + credit.to_d + foc.to_d + card.to_d + accept_credit.to_d
-# all_payments = cash.to_d + credit.to_d + foc.to_d + card.to_d + accept_credit.to_d
-# payments = { void_amount: void, cash_amount: cash, credit_amount: credit,accept_credit_amount: accept_credit, foc_amount: foc, card_amount: card, grand_total: all_payments , cashier_station_name: shift.cashier_station_name, opening_date: shift.opening_date, closing_date: shift.closing_date, rounding_adj: rounding_adj }
-
-# sale_arr.push(payments)
-# end
-
-# return sale_arr
-# end
-
-# def self.get_receipt_no_list(from,to)
-# sale = Sale.where("sale_status=? and receipt_date between ? and ?","completed",from,to)
-# end
-
def self.get_by_shift_sale(from,to,status)
query = ShiftSale.select("shift_sales.id ,shift_started_at AS opening_date,shift_closed_at As closing_date," +
" grand_total AS grand_total, cash_sales AS cash," +
@@ -604,7 +538,7 @@ def self.get_item_query()
end
- def self.get_by_shift_items(shift_sale_range, shift, from, to, status, report_type)
+ def self.get_by_shift_items(shift_sale_range, shift, from, to, status)
# date_type_selection = get_sql_function_for_report_type(report_type)
@@ -616,11 +550,12 @@ def self.get_item_query()
total_foc_amount = 0
total_grand_total = 0
- if shift == '[]'
+ if shift.blank?
### => get all sales range in shift_sales
query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift_sale_range.to_a)
discount_query = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:total_discount)
- sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_ - sales.amount_changed) else 0 end) as card_amount,
+ change_amount = Sale.where("sales.shift_sale_id IN (?) and sale_status ='completed'", shift_sale_range.to_a).sum(:amount_changed)
+ sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
@@ -633,11 +568,11 @@ def self.get_item_query()
total_foc_amount += s_c.foc_amount.to_f
end
total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
-
- elsif shift_sale_range == '[]'
+ else
query = query.where("sales.shift_sale_id IN (?) and sale_status='completed'",shift.to_a)
discount_query = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:total_discount)
- sale_cash = Sale.select("SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
+ change_amount = Sale.where("sales.shift_sale_id in (?) and sale_status= 'completed' ", shift.to_a).sum(:amount_changed)
+ sale_cash = Sale.select("SUM(case when (sale_payments.payment_method ='mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
@@ -649,31 +584,39 @@ def self.get_item_query()
total_credit_amount += s_c.credit_amount.to_f
total_foc_amount += s_c.foc_amount.to_f
end
- total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
-
- else
- query = query.where("receipt_date between ? and ? and sale_status=?",from,to,'completed')
- sale_cash = Sale.select("sales.total_discount as total_discount,
- SUM(case when (sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar') then (sale_payments.payment_amount) else 0 end) as card_amount,
- SUM(case when (sale_payments.payment_method='cash') then (sale_payments.payment_amount) else 0 end) as cash_amount,
- SUM(case when (sale_payments.payment_method='creditnote') then (sale_payments.payment_amount) else 0 end) as credit_amount,
- SUM(case when (sale_payments.payment_method='foc') then (sale_payments.payment_amount) else 0 end) as foc_amount")
- .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
- .where("sales.shift_sale_id in (?) and sale_status = 'completed' ", shift.to_a)
-
- sale_cash.each do |s_c|
- total_cash_amount += s_c.cash_amount.to_f
- total_card_amount += s_c.card_amount.to_f
- total_credit_amount += s_c.credit_amount.to_f
- total_foc_amount += s_c.foc_amount.to_f
- discount_query = s_c.total_discount.to_f
- end
- total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
-
+ total_grand_total = total_cash_amount.to_f + total_card_amount.to_f + total_credit_amount.to_f
+
end
- return query, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total
- end
+ return query, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount
+end
+
+def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_type)
+ ## => left join -> show all sales although no orders
+ if payment_type.blank?
+ payment_type = ''
+ else
+ if payment_type == 'card'
+ payment_type = " and sale_payments.payment_method = 'mpu' or sale_payments.payment_method = 'visa' or sale_payments.payment_method = 'master' or sale_payments.payment_method = 'jcb' or sale_payments.payment_method = 'paypar'"
+ else
+ payment_type = " and sale_payments.payment_method = '#{payment_type}'"
+ end
+ end
+ puts payment_type
+
+ query = Sale.all
+ if shift.present?
+ query = query.where("sales.shift_sale_id in (?) #{payment_type} and sale_status= 'completed' and sale_payments.payment_amount != 0", shift.to_a)
+ .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
+ .group("sales.sale_id")
+ else
+ query = query .where("sale_status='completed' #{payment_type} and sale_payments.payment_amount != 0 and sales.shift_sale_id in (?)",shift_sale_range.to_a)
+ .joins("join sale_payments on sale_payments.sale_id = sales.sale_id")
+ .group("sales.sale_id")
+ end
+
+end
+
def self.get_separate_tax(from,to,payment_method=nil)
@@ -692,7 +635,7 @@ end
cash = 0.0
self.sale_payments.each do |pay|
if pay.payment_method == 'cash'
- cash = pay.payment_amount
+ cash = pay.payment_amount-self.amount_changed
end
end
return cash
diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb
index 300935d9..8df6f1c0 100644
--- a/app/models/sale_payment.rb
+++ b/app/models/sale_payment.rb
@@ -261,20 +261,25 @@ class SalePayment < ApplicationRecord
end
self.sale.sale_status = "completed"
- response = rebat(sObj)
+ if MembershipSetting.find(1).rebate
+ response = rebat(sObj)
- if response["status"] == true
- self.sale.rebate_status = 'true'
- end
- if response["status"] == false
- self.sale.rebate_status = 'false'
- end
+ if !response.nil?
+ if response["status"] == true
+ self.sale.rebate_status = 'true'
+ end
+ if response["status"] == false
+ self.sale.rebate_status = 'false'
+ end
- if response[:status] == false
- self.sale.rebate_status = 'false'
- end
- if response[:status] == "no_member"
- self.sale.rebate_status = nil
+ if response[:status] == false
+ self.sale.rebate_status = 'false'
+ end
+ if response[:status] == "no_member"
+ self.sale.rebate_status = nil
+ end
+ end
+ puts "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr"
end
self.sale.save!
diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb
index a88cd8d7..335ab131 100644
--- a/app/models/seed_generator.rb
+++ b/app/models/seed_generator.rb
@@ -60,8 +60,15 @@ class SeedGenerator < ApplicationRecord
seed.save
end
- padding_len = 5 - prefix.length
- next_code = prefix + seed.current.to_s.to_s.rjust((4-prefix.length)+1,'0')
+
+ if prefix.length == 1
+ padding_len = 5 - prefix.length
+ count = 4-prefix.length
+ else prefix.length == 2
+ padding_len = 6 - prefix.length
+ count = 5-prefix.length
+ end
+ next_code = prefix + seed.current.to_s.to_s.rjust((count)+1,'0')
return next_code
end
end
diff --git a/app/views/crm/customers/_new_form.html.erb b/app/views/crm/customers/_new_form.html.erb
index 66a16b2b..8b84b4b9 100644
--- a/app/views/crm/customers/_new_form.html.erb
+++ b/app/views/crm/customers/_new_form.html.erb
@@ -46,11 +46,11 @@
- <%= f.input :nrc_no, :class => "form-control nrc_no" %>
+ <%= f.input :nrc_no,:label => "NRC No", :class => "form-control nrc_no" %>