diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 84d72f66..0700ce0b 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -19,10 +19,6 @@ class HomeController < ApplicationController if @employee != nil session[:session_token] = @employee.token_session - - #if cashier => already opening cahshier? - - redirect_to origami_root_path route_by_role(@employee) else render :show, flash[:notice] => "Invalid PIN for Employee. Please try again!" @@ -41,7 +37,7 @@ class HomeController < ApplicationController redirect_to dashboard_path elsif @employee.role == "cashier" session[:session_token] = @employee.token_session - redirect_to origami_root_path + route_by_role(@employee) elsif @employee.role == "manager" session[:session_token] = @employee.token_session redirect_to dashboard_path @@ -84,13 +80,13 @@ class HomeController < ApplicationController redirect_to dashboard_path elsif employee.role == "cashier" #check if cashier has existing open cashier - - # if !ShiftSale.current_open_shift(employee).nil? - # redirect_to origami_root_path - # else + shift = ShiftSale.current_open_shift(employee) + if !shift.nil? + redirect_to origami_root_path + else redirect_to new_origami_shift_path - # end - elsif employee.role == "checker" + end + elsif employee.role == "manager" redirect_to oqs_root_path elsif employee.role == "waiter" redirect_to oqs_root_path diff --git a/app/controllers/origami/home_controller_bk.rb b/app/controllers/origami/home_controller_bk.rb index 1aca9b2d..5496cca5 100644 --- a/app/controllers/origami/home_controller_bk.rb +++ b/app/controllers/origami/home_controller_bk.rb @@ -19,9 +19,9 @@ class Origami::HomeController < BaseOrigamiController @orders = Order.get_orders() end - def item_show - selection(params[:booking_id],1) - end + # def item_show + # selection(params[:booking_id],1) + # end def selection(selected_id, is_ajax) str = [] @@ -37,8 +37,8 @@ class Origami::HomeController < BaseOrigamiController @order_details = OrderItem.get_order_items_details(params[:booking_id]) @order_details.each do |ord_detail| str.push(ord_detail) - end - end + end + end if is_ajax == 1 render :json => str.to_json diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 4cd17cce..b20c4d7b 100644 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -1,4 +1,5 @@ -class Origami::ShiftsController < ApplicationController +class Origami::ShiftsController < BaseOrigamiController + def index end @@ -6,6 +7,13 @@ class Origami::ShiftsController < ApplicationController end def new + @float = Lookup.where('lookup_type=?','float') + end + + def create + opening_balance = params[:opening_balance] + @shift = ShiftSale.new + @shift.create(opening_balance,current_user) end def edit diff --git a/app/models/sale.rb b/app/models/sale.rb index 8f7f17d8..cac1308b 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -263,7 +263,6 @@ class Sale < ApplicationRecord end - private def product_get_unit_price(item_code) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 8b28c946..7f39aa18 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -247,6 +247,10 @@ class SalePayment < ApplicationRecord end self.sale.sale_status = "completed" self.sale.save! + shift = ShiftSale.current_open_shift(self.sale.cashier_id) + if shift + shift.update(self.sale) + end table_update_status(sObj) rebat(sObj) end diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 97d7ab0e..ea7f1132 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -19,7 +19,33 @@ class ShiftSale < ApplicationRecord def self.current_open_shift(current_user) #if current_user #find open shift where is open today and is not closed and login by current cashier - @shift = ShiftSale.where("cast(shift_started_at as date) = #{DateTime.now.to_date} and shift_started_at is null and employee_id = #{current_user.id}").limit(1) + today_date = DateTime.now.strftime("%Y-%m-%d") + shift = ShiftSale.where("TO_CHAR(shift_started_at, 'YYYY-MM-DD')=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user.id}",today_date).take + + return shift #end end + + def create(opening_balance,current_user) + self.cashier_terminal_id = CashierTerminal.first.id + self.shift_started_at = DateTime.now + self.employee_id = current_user.id + self.opening_balance = opening_balance + self.save + end + + def update(sale) + saleobj = Sale.find(sale) + self.total_revenue = self.total_revenue + saleobj.total_amount + self.total_discounts = self.total_discounts + saleobj.total_discount + self.total_taxes = self.total_taxes + saleobj.total_tax + self.grand_total = self.grand_total + saleobj.grand_total + # self.nett_sales = + # self.cash_sales = + # self.credit_sales = + # self.other_sales = + # self.commercial_taxes = + self.save + + end end diff --git a/app/views/origami/shifts/create.json.jbuilder b/app/views/origami/shifts/create.json.jbuilder new file mode 100644 index 00000000..08bf292c --- /dev/null +++ b/app/views/origami/shifts/create.json.jbuilder @@ -0,0 +1 @@ +json.status true diff --git a/app/views/origami/shifts/new.html.erb b/app/views/origami/shifts/new.html.erb index 4a216f69..16c2aa10 100644 --- a/app/views/origami/shifts/new.html.erb +++ b/app/views/origami/shifts/new.html.erb @@ -1,2 +1,46 @@ -
Find me in app/views/origami/shifts/new.html.erb
+| <%= float.name %> | ++ |
|---|---|
| Total | ++ |