diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 29e9082a..f30297c7 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -10,6 +10,7 @@ class HomeController < ApplicationController @login_form.emp_id = params[:login_form][:emp_id] @login_form.password = params[:login_form][:password] @employee = Employee.login(@login_form.emp_id, @login_form.password) +<<<<<<< HEAD if @employee != nil if @employee.role == "administrator" @@ -24,6 +25,17 @@ class HomeController < ApplicationController else redirect_to origami_root_path, :notice => "Username and Password dosn't match!" end +======= + if @employee.role == "administrator" + session[:session_token] = @employee.token_session + redirect_to dashboard_path + elsif @employee.role == "cashier" + session[:session_token] = @employee.token_session + redirect_to origami_root_path + else + render :index + end +>>>>>>> 7dffd668eaee6ab82621fd4bae150525ded79df1 end diff --git a/app/controllers/transactions/orders_controller.rb b/app/controllers/transactions/orders_controller.rb index 2d3a819e..35cefe6f 100644 --- a/app/controllers/transactions/orders_controller.rb +++ b/app/controllers/transactions/orders_controller.rb @@ -13,7 +13,7 @@ class Transactions::OrdersController < ApplicationController end end - @orders = Kaminari.paginate_array(orders).page(params[:page]).per(2) + @orders = Kaminari.paginate_array(orders).page(params[:page]).per(50) respond_to do |format| format.html # index.html.erb format.json { render json: @orders } diff --git a/app/controllers/transactions/sales_controller.rb b/app/controllers/transactions/sales_controller.rb index c8ecb725..b1c28e98 100644 --- a/app/controllers/transactions/sales_controller.rb +++ b/app/controllers/transactions/sales_controller.rb @@ -10,12 +10,18 @@ class Transactions::SalesController < ApplicationController today = Date.today if receipt_no.nil? - @sales = Sale.order("sale_id") - #@products = Product.order("name").page(params[:page]).per(5) + sales = Sale.order("sale_id desc") else - @sales = Sale.search(receipt_no) - end - @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) + order = Sale.search(receipt_no) + if order.count > 0 + sales = order + else + sales = Sale.order("sale_id desc") + + end + end + @sales = Kaminari.paginate_array(sales).page(params[:page]).per(50) + respond_to do |format| format.html # index.html.erb format.json { render json: @sales } diff --git a/app/models/order.rb b/app/models/order.rb index bac7cd20..83eb9418 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -25,7 +25,7 @@ class Order < ApplicationRecord booking = nil if self.new_booking - + booking = Booking.create({:dining_facility_id => self.table_id,:type => "TableBooking", :checkin_at => Time.now.utc, :checkin_by => self.employee_name, :booking_status => "assign" }) @@ -228,11 +228,11 @@ class Order < ApplicationRecord bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id") - .joins("left join orders on orders.order_id = booking_orders.order_id") + .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::TABLE_TYPE,true) - .group("bookings.booking_id") - # For PG + .group("bookings.booking_id,orders.status,sales.receipt_no,sales.sale_status,orders.order_id,sales.customer_id,sales.sale_id,dining_facilities.name") + # For PG # booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true # sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id end @@ -246,8 +246,8 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("sales.sale_status='completed'") - .group("sales.sale_id") - # For PG + .group("sales.sale_id,orders.status,orders.order_id,bookings.booking_id,dining_facilities.name") + # For PG #bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id end @@ -262,8 +262,8 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("(orders.status = 'new' or orders.status = 'billed') and (dining_facilities.type=? and dining_facilities.is_active=?)",DiningFacility::ROOM_TYPE,true) - .group("bookings.booking_id") - # For PG + .group("bookings.booking_id,sales.receipt_no,orders.status,orders.order_id,sales.customer_id,sales.sale_status,orders.customer_id,sales.sale_id,dining_facilities.name") + # For PG # booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true # sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id end @@ -292,7 +292,7 @@ class Order < ApplicationRecord .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id") .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") - .where("(orders.status = 'new' or orders.status = 'billed')") + .where("(orders.status = 'new' or orders.status = 'billed')") # orders = Order.select("orders.order_id as order_id,sales.receipt_no,orders.status as order_status, sales.sale_status as sale_status, # orders.order_id as order_id,sales.customer_id as sale_customer_id,orders.customer_id as order_customer_id @@ -305,7 +305,7 @@ class Order < ApplicationRecord # left join sales on sales.sale_id = sale_orders.sale_id") # .where("(orders.status = 'new' or orders.status = 'billed')") # .group("orders.order_id") - # For PG + # For PG # .where("dining_facilities.is_active=? and orders.date between ? and ?",true,from,to) # .group("orders.order_id,order_items.order_items_id,dining_facilities.name,sales.receipt_no,bookings.booking_id,sales.sale_id,orders.customer_id") @@ -314,7 +314,7 @@ class Order < ApplicationRecord def self.search(search) if search # find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"]) - where("order_id LIKE ?", "%#{search}%") + where("order_id LIKE ?", "%#{search}%") else find(:all) end diff --git a/app/models/sale.rb b/app/models/sale.rb index 426ece2d..dee4c2f7 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -13,7 +13,7 @@ class Sale < ApplicationRecord has_many :sale_payments has_many :sale_orders has_many :bookings - + scope :open_invoices, -> { where("sale_status = 'new' and receipt_date BETWEEN '#{DateTime.now.utc.end_of_day}' AND '#{DateTime.now.utc.beginning_of_day}'") } def generate_invoice_from_booking(booking_id, requested_by) @@ -59,9 +59,8 @@ class Sale < ApplicationRecord # set cashier by current login self.cashier_id = requested_by.id self.cashier_name = requested_by.name - - self.requested_by = requested_by.name + self.requested_at = DateTime.now.utc Rails.logger.debug "Order -> #{order.id} | order_status -> #{order.status}" @@ -267,7 +266,7 @@ class Sale < ApplicationRecord def self.search(search) if search # find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"]) - where("receipt_no LIKE ?", "%#{search}%",) + where("receipt_no LIKE ?", "%#{search}%",) else find(:all) end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index fc085259..731fa321 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -212,7 +212,7 @@ class SalePayment < ApplicationRecord def sale_update_payment_status(paid_amount) #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f - + self.sale.save! self.sale.amount_changed = self.sale.amount_received.to_f - self.sale.grand_total.to_f all_received_amount = 0.0 sObj = Sale.find(self.sale_id) 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 new file mode 100644 index 00000000..1b4082f5 --- /dev/null +++ b/app/views/reports/receipt_no/_shift_sale_report_filter.html.erb @@ -0,0 +1,211 @@ +