diff --git a/.gitignore b/.gitignore index 9dde67bb..c29faad2 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,7 @@ config/deploy/config/* # Ignore Byebug command history file. .byebug_history + +# Gem files +Gemfile +Gemfile.lock \ No newline at end of file diff --git a/Gemfile b/Gemfile index d64ba992..08464196 100644 --- a/Gemfile +++ b/Gemfile @@ -9,8 +9,14 @@ end # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '~> 5.1.0' # Use mysql as the database for Active Record -#gem 'mysql2', '>= 0.3.18', '< 0.5' -gem 'pg' +gem 'mysql2', '>= 0.3.18', '< 0.5' + +#Use PosgreSQL +#gem 'pg' + +# redis server for cable +gem 'redis', '~> 3.0' + # Use Puma as the app server gem 'puma', '~> 3.0' # Use SCSS for stylesheets @@ -37,6 +43,8 @@ gem 'to_xls-rails' #Reporting gem #gem 'compendium' +# Pagination +gem 'kaminari', :git => "git://github.com/amatsuda/kaminari.git", :branch => 'master' # Use jquery as the JavaScript library gem 'jquery-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 3627d882..0c3a3a27 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,21 @@ +GIT + remote: git://github.com/amatsuda/kaminari.git + revision: c3c853a944cd2bff072ae05e48c563b2c9a29597 + branch: master + specs: + kaminari (1.0.1) + activesupport (>= 4.1.0) + kaminari-actionview (= 1.0.1) + kaminari-activerecord (= 1.0.1) + kaminari-core (= 1.0.1) + kaminari-actionview (1.0.1) + actionview + kaminari-core (= 1.0.1) + kaminari-activerecord (1.0.1) + activerecord + kaminari-core (= 1.0.1) + kaminari-core (1.0.1) + GEM remote: https://rubygems.org/ specs: @@ -48,9 +66,9 @@ GEM sass (>= 3.4.19) builder (3.2.3) byebug (9.0.6) - coffee-rails (4.2.1) + coffee-rails (4.2.2) coffee-script (>= 2.2.0) - railties (>= 4.0.0, < 5.2.x) + railties (>= 4.0.0) coffee-script (2.4.1) coffee-script-source execjs @@ -96,7 +114,8 @@ GEM mini_portile2 (2.1.0) minitest (5.10.2) multi_json (1.12.1) - nio4r (2.0.0) + mysql2 (0.4.6) + nio4r (2.1.0) nokogiri (1.7.2) mini_portile2 (~> 2.1.0) pdf-core (0.7.0) @@ -231,13 +250,16 @@ DEPENDENCIES font-awesome-rails jbuilder (~> 2.5) jquery-rails + kaminari! listen (~> 3.0.5) + mysql2 (>= 0.3.18, < 0.5) pg prawn prawn-table puma (~> 3.0) rack-cors rails (~> 5.1.0) + redis (~> 3.0) rspec-rails (~> 3.5) sass-rails (~> 5.0) schema_to_scaffold @@ -255,4 +277,4 @@ DEPENDENCIES web-console (>= 3.3.0) BUNDLED WITH - 1.14.6 + 1.15.0 diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index fc91e269..091b6822 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -15,3 +15,23 @@ //= require jquery_ujs //= require turbolinks //= require cable + +$(document).ready(function(){ + $('.queue_station').on('click',function(){ + var title=$(this).children().children('.card-title').text(); + var titles=title.split(' '); + + var orderBy=$(this).children().children().children().children('.order-by').text(); + var orderAt=$(this).children().children().children().children('.order-at').text(); + var orderCustomer=$(this).children().children('.order-customer').text(); + + $('#order-title').text($('#order-title').text() + titles[0]); + $('#order-by').text(orderBy); + $('#order-at').text(orderAt); + $('#order-customer').text(orderCustomer); + $('#order-from').text(titles[0]); + + $('#order-items').text(titles[1]); + $('#order-qty').text(titles[2].substr(2).replace(']','')); + }); +}); diff --git a/app/assets/javascripts/cable.js b/app/assets/javascripts/cable.js index 71ee1e66..739aa5f0 100644 --- a/app/assets/javascripts/cable.js +++ b/app/assets/javascripts/cable.js @@ -1,5 +1,5 @@ // Action Cable provides the framework to deal with WebSockets in Rails. -// You can generate new channels where WebSocket features live using the rails generate channel command. +// You can generate new channels where WebSocket features live using the `rails generate channel` command. // //= require action_cable //= require_self diff --git a/app/assets/javascripts/channels/order_queue_station.js b/app/assets/javascripts/channels/order_queue_station.js new file mode 100644 index 00000000..00151e5e --- /dev/null +++ b/app/assets/javascripts/channels/order_queue_station.js @@ -0,0 +1,24 @@ +App.order_queue_station = App.cable.subscriptions.create("OrderQueueStationChannel", { + connected: function() {}, + + disconnected: function() {}, + + received: function(message) { + alert(message); + }, + + order: function(message) { + return this.perform('order', { + message: message + }); + } +}); + +// $(function(){ +// $("#submit_order").on('click', function(event) { +// var orderData=$("#new_order").serializeObject(); +// App.order_station.order(orderData); +// //orderData=''; +// return event.preventDefault(); +// }); +// }); diff --git a/app/assets/javascripts/transactions/sales.coffee b/app/assets/javascripts/transactions/sales.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/transactions/sales.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/transactions/sales.scss b/app/assets/stylesheets/transactions/sales.scss new file mode 100644 index 00000000..2ab00c12 --- /dev/null +++ b/app/assets/stylesheets/transactions/sales.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the transactions/Sales controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/channels/application_cable/channel.rb b/app/channels/application_cable/channel.rb index d6726972..a66bc071 100644 --- a/app/channels/application_cable/channel.rb +++ b/app/channels/application_cable/channel.rb @@ -1,4 +1,14 @@ module ApplicationCable - class Channel < ActionCable::Channel::Base - end + class Channel < ActionCable::Channel::Base + end + # Order Queue Station Channel + class OrderChannel < ActionCable::Channel::Base + + end + + # Order Queue Station Channel + class OQSChannel < ActionCable::Channel::Base + + end + end diff --git a/app/channels/order_queue_station_channel.rb b/app/channels/order_queue_station_channel.rb new file mode 100644 index 00000000..8206c64b --- /dev/null +++ b/app/channels/order_queue_station_channel.rb @@ -0,0 +1,13 @@ +class OrderQueueStationChannel < ApplicationCable::Channel + def subscribed + stream_from "order_queue_station_channel" + end + + def unsubscribed + # Any cleanup needed when channel is unsubscribed + end + + def order(message) + # ToDo + end +end diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index d0fe2a77..57f2e48c 100644 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -37,6 +37,7 @@ class Api::OrdersController < Api::ApiController #Create Table Booking or Room Booking if !params["booking_id"].nil? && params[:booking_id].to_i > 0 @order.new_booking = false + # @order.new_booking = true @order.booking_id = params[:booking_id] end diff --git a/app/controllers/crm/home_controller.rb b/app/controllers/crm/home_controller.rb index ee29270a..2a7153f8 100644 --- a/app/controllers/crm/home_controller.rb +++ b/app/controllers/crm/home_controller.rb @@ -1,5 +1,23 @@ class Crm::HomeController < BaseCrmController def index + + # @booking = Booking.all + + @booking = Booking.select("bookings.id as booking_id, + bookings.checkin_at, + bookings.checkin_by, + bookings.dining_facility_id, + od.customer_id as customer, + od.item_count as count, + odt.id as order_item_id, + odt.item_name as item_name") + .joins("join booking_orders as bko ON bko.booking_id = bookings.id") + .joins("right join orders as od ON od.id = bko.order_id") + .joins("right join order_items as odt ON odt.order_id=od.id") + .order("bookings.id DESC") + + @customer = Customer.all + end def show end diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index acf99e41..0f73d20d 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -1,6 +1,31 @@ class Oqs::HomeController < BaseOqsController def index + @queue_stations=OrderQueueStation.all + + #sample Data + @queue_items_details = { :queue_id => 1, :order_id => 1, :station_name => 'Queue Station 1', :zone => 'Table4', :item_name => 'beef', :price => 10.00, :qty => 2, :customer => 'Wathon', :item_order_by => 'Yan', :created_at => '2007-05-17'} + # @queue_items_details = OrderItem.select("oqs as queue_id, oqs.station_name, oqs.is_active, oqpz.zone_id, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, odt.created_at") + # .joins("join order_queue_process_by_zones as oqpz ON oqpz.order_queue_station_id = order_queue_items.order_queue_station_id") + # .joins("right join order_queue_stations as oqs ON oqs.id = order_queue_items.order_queue_station_id") + # .joins("right join orders as od ON od.id = order_queue_items.order_id") + # .joins("right join order_items as odt ON odt.item_code = order_queue_items.item_code") + # .order("odt.item_name DESC") + + + + # Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price, + # order_items.id as order_items_id,dining_facilities.name as table_name") + # .joins("left join booking_orders on booking_orders.order_id = orders.id + # left join bookings on bookings.id = booking_orders.id + # left join dining_facilities on dining_facilities.id = bookings.dining_facility_id + # left join order_items on order_items.order_id = orders.id") + # .where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,"dine_in",true) + # .group("orders.id") end + def show end end + + + diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 8cbc8e55..cbca1424 100644 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -1,6 +1,15 @@ class Origami::HomeController < BaseOrigamiController def index + @order_table = Order.get_order_table() + @order_rooms = Order.get_order_rooms() + @orders = Order.get_orders() end def show + str = [] + @order_details = OrderItem.get_order_items_details(params[:order_id]) + @order_details.each do |ord_detail| + str.push(ord_detail) + end + render :json => str.to_json end end diff --git a/app/controllers/settings/menu_categories_controller.rb b/app/controllers/settings/menu_categories_controller.rb index daa76d62..d7f373aa 100644 --- a/app/controllers/settings/menu_categories_controller.rb +++ b/app/controllers/settings/menu_categories_controller.rb @@ -5,7 +5,7 @@ class Settings::MenuCategoriesController < ApplicationController # GET /settings/menu_categories # GET /settings/menu_categories.json def index - @settings_menu_categories = MenuCategory.all + @settings_menu_categories = MenuCategory.all.page(params[:page]).per(10) end # GET /settings/menu_categories/1 @@ -63,7 +63,7 @@ class Settings::MenuCategoriesController < ApplicationController # DELETE /settings/menu_categories/1 # DELETE /settings/menu_categories/1.json def destroy - @settings_menu_category.destroy + # @settings_menu_category.destroy respond_to do |format| format.html { redirect_to settings_menu_categories_path, notice: 'Menu category was successfully destroyed.' } format.json { head :no_content } diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index b10f31c9..e0ecde30 100644 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -4,12 +4,13 @@ class Settings::MenusController < ApplicationController # GET /settings/menus # GET /settings/menus.json def index - @settings_menus = Menu.all + @settings_menus = Menu.all.page(params[:page]).per(10) end # GET /settings/menus/1 # GET /settings/menus/1.json def show + @settings_menu_categories = @settings_menu.menu_categories.page(params[:page]).per(10) end # GET /settings/menus/new @@ -25,7 +26,7 @@ class Settings::MenusController < ApplicationController # POST /settings/menus.json def create @settings_menu = Menu.new(settings_menu_params) - + @settings_menu.created_by = current_login_employee.name respond_to do |format| if @settings_menu.save format.html { redirect_to settings_menus_path, notice: 'Menu was successfully created.' } @@ -42,7 +43,7 @@ class Settings::MenusController < ApplicationController def update respond_to do |format| if @settings_menu.update(settings_menu_params) - format.html { redirect_to settings_menu_path(@settings_menu), notice: 'Menu was successfully updated.' } + format.html { redirect_to settings_menus_path, notice: 'Menu was successfully updated.' } format.json { render :show, status: :ok, location: @settings_menu } else format.html { render :edit } diff --git a/app/controllers/settings/set_menu_items_controller.rb b/app/controllers/settings/set_menu_items_controller.rb index 1f227246..438b2f08 100644 --- a/app/controllers/settings/set_menu_items_controller.rb +++ b/app/controllers/settings/set_menu_items_controller.rb @@ -1,12 +1,12 @@ class Settings::SetMenuItemsController < ApplicationController before_action :set_settings_menu_item, only: [:show, :edit, :update, :destroy] - before_action :set_settings_menu_category, only: [:index, :show, :edit, :new] + before_action :set_settings_menu_category, only: [:index, :show, :edit, :new, :update] # GET /settings/menu_items # GET /settings/menu_items.json def index @settings_menu_items = @category.menu_items end - + # GET /settings/menu_items/1 # GET /settings/menu_items/1.json def show @@ -25,10 +25,13 @@ class Settings::SetMenuItemsController < ApplicationController # POST /settings/menu_items.json def create @settings_menu_item = MenuItem.new(settings_menu_item_params) - + if params[:simple_menu_item][:menu_item_id] == '' + @settings_menu_item.menu_category_id = params[:menu_category_id] + end + @settings_menu_item.created_by = current_login_employee.name respond_to do |format| if @settings_menu_item.save - format.html { redirect_to settings_menu_items_path, notice: 'Menu item was successfully created.' } + format.html { redirect_to settings_menu_category_set_menu_items_path, notice: 'Menu item was successfully created.' } format.json { render :show, status: :created, location: @settings_menu_item } else format.html { render :new } @@ -42,7 +45,7 @@ class Settings::SetMenuItemsController < ApplicationController def update respond_to do |format| if @settings_menu_item.update(settings_menu_item_params) - format.html { redirect_to settings_menu_item_path(@settings_menu_item), notice: 'Menu item was successfully updated.' } + format.html { redirect_to settings_menu_category_set_menu_items_path, notice: 'Menu item was successfully updated.' } format.json { render :show, status: :ok, location: @settings_menu_item } else format.html { render :edit } @@ -54,9 +57,9 @@ class Settings::SetMenuItemsController < ApplicationController # DELETE /settings/menu_items/1 # DELETE /settings/menu_items/1.json def destroy - @settings_menu_item.destroy + # @settings_menu_item.destroy respond_to do |format| - format.html { redirect_to settings_menu_items_path, notice: 'Menu item was successfully destroyed.' } + format.html { redirect_to settings_menu_category_set_menu_items_path, notice: 'Menu item was successfully destroyed.' } format.json { head :no_content } end end @@ -73,6 +76,6 @@ class Settings::SetMenuItemsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_menu_item_params - params.require(:menu_item).permit(:item_code, :name, :alt_name, :type, :menu_category_id, :menu_item_id, :min_qty, :min_selectable_item, :max_selectable_item, :created_by) + params.require(:set_menu_item).permit(:item_code, :name, :alt_name, :type, :menu_category_id, :menu_item_id, :min_qty, :min_selectable_item, :max_selectable_item, :created_by) end end diff --git a/app/controllers/settings/simple_menu_items_controller.rb b/app/controllers/settings/simple_menu_items_controller.rb index c9114330..e81d6817 100644 --- a/app/controllers/settings/simple_menu_items_controller.rb +++ b/app/controllers/settings/simple_menu_items_controller.rb @@ -1,12 +1,12 @@ class Settings::SimpleMenuItemsController < ApplicationController before_action :set_settings_menu_item, only: [:show, :edit, :update, :destroy] - before_action :set_settings_menu_category, only: [:index, :show, :edit, :new] + before_action :set_settings_menu_category, only: [:index, :show, :edit, :new, :update] # GET /settings/menu_items # GET /settings/menu_items.json def index @settings_menu_items = @category.menu_items end - + # GET /settings/menu_items/1 # GET /settings/menu_items/1.json def show @@ -25,10 +25,13 @@ class Settings::SimpleMenuItemsController < ApplicationController # POST /settings/menu_items.json def create @settings_menu_item = MenuItem.new(settings_menu_item_params) - + if params[:simple_menu_item][:menu_item_id] == '' + @settings_menu_item.menu_category_id = params[:menu_category_id] + end + @settings_menu_item.created_by = current_login_employee.name respond_to do |format| if @settings_menu_item.save - format.html { redirect_to settings_menu_items_path, notice: 'Menu item was successfully created.' } + format.html { redirect_to settings_menu_category_simple_menu_items_path, notice: 'Menu item was successfully created.' } format.json { render :show, status: :created, location: @settings_menu_item } else format.html { render :new } @@ -42,7 +45,7 @@ class Settings::SimpleMenuItemsController < ApplicationController def update respond_to do |format| if @settings_menu_item.update(settings_menu_item_params) - format.html { redirect_to settings_menu_item_path(@settings_menu_item), notice: 'Menu item was successfully updated.' } + format.html { redirect_to settings_menu_category_simple_menu_items_path, notice: 'Menu item was successfully updated.' } format.json { render :show, status: :ok, location: @settings_menu_item } else format.html { render :edit } @@ -54,9 +57,9 @@ class Settings::SimpleMenuItemsController < ApplicationController # DELETE /settings/menu_items/1 # DELETE /settings/menu_items/1.json def destroy - @settings_menu_item.destroy + # @settings_menu_item.destroy respond_to do |format| - format.html { redirect_to settings_menu_items_path, notice: 'Menu item was successfully destroyed.' } + format.html { redirect_to settings_menu_category_simple_menu_items_path, notice: 'Menu item was successfully destroyed.' } format.json { head :no_content } end end diff --git a/app/controllers/transactions/sales_controller.rb b/app/controllers/transactions/sales_controller.rb new file mode 100644 index 00000000..ea9e8ccd --- /dev/null +++ b/app/controllers/transactions/sales_controller.rb @@ -0,0 +1,74 @@ +class Transactions::SalesController < ApplicationController + before_action :set_transactions_sale, only: [:show, :edit, :update, :destroy] + + # GET /transactions/sales + # GET /transactions/sales.json + def index + @transactions_sales = Sale.all + end + + # GET /transactions/sales/1 + # GET /transactions/sales/1.json + def show + end + + # GET /transactions/sales/new + def new + @transactions_sale = Sale.new + end + + # GET /transactions/sales/1/edit + def edit + end + + # POST /transactions/sales + # POST /transactions/sales.json + def create + @transactions_sale = Sale.new(transactions_sale_params) + + respond_to do |format| + if @transactions_sale.save + format.html { redirect_to @transactions_sale, notice: 'Sale was successfully created.' } + format.json { render :show, status: :created, location: @transactions_sale } + else + format.html { render :new } + format.json { render json: @transactions_sale.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /transactions/sales/1 + # PATCH/PUT /transactions/sales/1.json + def update + respond_to do |format| + if @transactions_sale.update(transactions_sale_params) + format.html { redirect_to @transactions_sale, notice: 'Sale was successfully updated.' } + format.json { render :show, status: :ok, location: @transactions_sale } + else + format.html { render :edit } + format.json { render json: @transactions_sale.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /transactions/sales/1 + # DELETE /transactions/sales/1.json + def destroy + @transactions_sale.destroy + respond_to do |format| + format.html { redirect_to transactions_sales_url, notice: 'Sale was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_transactions_sale + @transactions_sale = Sale.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def transactions_sale_params + params.require(:transactions_sale).permit(:cashier_id, :cashier_name, :requested_by, :requested_at, :receipt_no, :receipt_date, :customer_id, :payment_status, :sale_status, :total_amount, :total_discount, :total_tax, :tax_type, :grand_total, :rounding_adjustment, :amount_received, :amount_changed) + end +end diff --git a/app/helpers/transactions/sales_helper.rb b/app/helpers/transactions/sales_helper.rb new file mode 100644 index 00000000..95aa5c87 --- /dev/null +++ b/app/helpers/transactions/sales_helper.rb @@ -0,0 +1,2 @@ +module Transactions::SalesHelper +end diff --git a/app/jobs/order_broadcast_job.rb b/app/jobs/order_broadcast_job.rb new file mode 100644 index 00000000..b29f4cd8 --- /dev/null +++ b/app/jobs/order_broadcast_job.rb @@ -0,0 +1,8 @@ +class OrderBroadcastJob < ApplicationJob + queue_as :default + + def perform(message) + order = Order.find(message) # message come as order_id + ApplicationCable.server.broadcast "order_queue_station_channel", order: order + end +end diff --git a/app/jobs/order_queue_processor_job.rb b/app/jobs/order_queue_processor_job.rb index 33380674..e9a8c13f 100644 --- a/app/jobs/order_queue_processor_job.rb +++ b/app/jobs/order_queue_processor_job.rb @@ -3,8 +3,9 @@ class OrderQueueProcessorJob < ApplicationJob def perform(order_id) # Do something later - #Order ID + #Order ID order = Order.find(order_id) + #Loop through the order stations and process the items #Execute orders and send to order stations if order diff --git a/app/models/dining_facility.rb b/app/models/dining_facility.rb index 692c6591..9a4f7a75 100644 --- a/app/models/dining_facility.rb +++ b/app/models/dining_facility.rb @@ -1,6 +1,9 @@ class DiningFacility < ApplicationRecord belongs_to :zone + TABLE_TYPE = "Table" + ROOM_TYPE = "Room" + default_scope { order('order_by asc') } scope :active, -> {where(is_active: true)} diff --git a/app/models/menu.rb b/app/models/menu.rb index 44daca13..ac9ea4d3 100644 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -1,8 +1,8 @@ class Menu < ApplicationRecord has_many :menu_categories, dependent: :destroy - validates_presence_of :name, :is_active, :valid_days, :valid_time_from, :valid_time_to - + validates_presence_of :name, :valid_days, :valid_time_from, :valid_time_to + validates_format_of :valid_days, :with => /\A([0-7]{1}(,[0-7]{1})*)?\Z/i, :on => :create #Default Scope to pull the active version only default_scope { where(is_active: true).order("created_at desc") } diff --git a/app/models/order.rb b/app/models/order.rb index 0bec3a1e..3f74284f 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -8,7 +8,6 @@ class Order < ApplicationRecord #internal references attributes for business logic control attr_accessor :items, :guest, :table_id, :new_booking, :booking_type, :employee_name, :booking_id - #Main Controller method to create new order - validate all inputs and generate new order # order_item : { # order_item_code : "", @@ -43,6 +42,9 @@ class Order < ApplicationRecord #Send order to queue one it done! process_order_queue + #send order to broadcast job + send_order_broadcast + return true, booking end @@ -198,7 +200,48 @@ class Order < ApplicationRecord #Process order items and send to order queue def process_order_queue - #Send to background job for processing + #Send to background job for processing OrderQueueProcessorJob.perform_later(self.id) end + + + #send order items and send to order queue + def send_order_broadcast + #Send to background job for processing + OrderBroadcastJob.perform_later(self.id) + end + + #Origami: Cashier : to view order type Table + def self.get_order_table + order_table = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price, + order_items.id as order_items_id,dining_facilities.name as table_name") + .joins("left join booking_orders on booking_orders.order_id = orders.id + left join bookings on bookings.id = booking_orders.id + left join dining_facilities on dining_facilities.id = bookings.dining_facility_id + left join order_items on order_items.order_id = orders.id") + .where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,"dine_in",true) + .group("orders.id") + end + #Origami: Cashier : to view order type Room + def self.get_order_rooms + order_rooms = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price, + order_items.id as order_items_id,dining_facilities.name as room_name") + .joins("left join booking_orders on booking_orders.order_id = orders.id + left join bookings on bookings.id = booking_orders.id + left join dining_facilities on dining_facilities.id = bookings.dining_facility_id + left join order_items on order_items.order_id = orders.id") + .where("dining_facilities.type=? and orders.order_type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,"dine_in",true) + .group("orders.id") + end + #Origami: Cashier : to view orders + def self.get_orders + orders = Order.select("orders.id as order_id,sum(order_items.qty*order_items.price) as total_price, + order_items.id as order_items_id,dining_facilities.name as table_or_room_name") + .joins("left join booking_orders on booking_orders.order_id = orders.id + left join bookings on bookings.id = booking_orders.id + left join dining_facilities on dining_facilities.id = bookings.dining_facility_id + left join order_items on order_items.order_id = orders.id") + .where("dining_facilities.is_active=?",true) + .group("orders.id") + end end diff --git a/app/models/order_item.rb b/app/models/order_item.rb index afba7d7e..f839ad99 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -33,4 +33,10 @@ class OrderItem < ApplicationRecord end + #Origami : Cashier : to show order items details + def self.get_order_items_details(order_id) + order_details = OrderItem.select("order_items.item_name,order_items.qty,order_items.price,(order_items.qty*order_items.price) as total_price") + .joins("left join orders on orders.id = order_items.order_id") + .where("order_items.order_id=?",order_id) + end end diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index b2feb596..b0619af2 100644 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -8,7 +8,7 @@ class OrderQueueStation < ApplicationRecord scope :active, -> {where(is_active: true)} - def process_order (order) + def process_order (order) oqs_stations = OrderQueueStation.active order_items = order.order_items @@ -20,10 +20,10 @@ class OrderQueueStation < ApplicationRecord #Loop through the processing items pq_items.each do |pq_item| #Processing through the looping items - order_items.each do |order_item| + order_items.each do |order_item| if (pq_item == order_item.item_code) #Same Order_items can appear in two location. - AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) end end diff --git a/app/models/sale_discount.rb b/app/models/sale_discount.rb deleted file mode 100644 index 1d18c856..00000000 --- a/app/models/sale_discount.rb +++ /dev/null @@ -1,3 +0,0 @@ -class SaleDiscount < ApplicationRecord - belongs_to :sale -end diff --git a/app/models/test.rb b/app/models/test.rb new file mode 100644 index 00000000..fe0afa77 --- /dev/null +++ b/app/models/test.rb @@ -0,0 +1,2 @@ +class Test < ApplicationRecord +end diff --git a/app/models/transactions.rb b/app/models/transactions.rb new file mode 100644 index 00000000..9cffb0d1 --- /dev/null +++ b/app/models/transactions.rb @@ -0,0 +1,5 @@ +module Transactions + def self.table_name_prefix + 'transactions_' + end +end diff --git a/app/views/crm/home/_booking.html.erb b/app/views/crm/home/_booking.html.erb new file mode 100644 index 00000000..cf983116 --- /dev/null +++ b/app/views/crm/home/_booking.html.erb @@ -0,0 +1,26 @@ + +
+ + <% @i = 0 %> + <% @booking.each do |booking| %> +
+
+

+ <%= @i += 1 %> . <%= booking.dining_facility.name %> + - <%= booking.item_name %> +

+

Medium, Fries, Salad +

+

+ + Order at <%= booking.checkin_at.strftime("%H,%m") %>, <%= booking.checkin_by %> + +

+
+ +
+ <% end %> + +
\ No newline at end of file diff --git a/app/views/crm/home/_customer.html.erb b/app/views/crm/home/_customer.html.erb new file mode 100644 index 00000000..ea643494 --- /dev/null +++ b/app/views/crm/home/_customer.html.erb @@ -0,0 +1,23 @@ + +
+ <% @customer.each do |customer| %> +
+
+ +

Name : <%= customer.name %>

+

Contact No : <%= customer.contact_no %>

+

Email : <%= customer.email %>

+
+
+ <% end %> + +
+
+

Card title

+

This card has supporting text below as a natural lead-in to additional content.

+

Last updated 3 mins ago

+
+
+ + +
\ No newline at end of file diff --git a/app/views/crm/home/_queue.html.erb b/app/views/crm/home/_queue.html.erb new file mode 100644 index 00000000..99c56f9e --- /dev/null +++ b/app/views/crm/home/_queue.html.erb @@ -0,0 +1,29 @@ +
+
+
+

9. Table 4 - Beef Steak [x3]

+

Well Done, Fries, Salad

+

+ Order at 12:23, Kyaw Lwin | + Printed at 12:23 | + Completed at 12:43 +

+ + +
+
+
+
+

9. Table 4 - Beef Steak [x3]

+

Well Done, Fries, Salad

+

Order at 12:23, Kyaw Lwin

+
+
+
+
+

9. Table 4 - Beef Steak [x3]

+

Well Done, Fries, Salad

+

Order at 12:23, Kyaw Lwin

+
+
+
\ No newline at end of file diff --git a/app/views/crm/home/index.html.erb b/app/views/crm/home/index.html.erb index c094b4a0..07e58652 100644 --- a/app/views/crm/home/index.html.erb +++ b/app/views/crm/home/index.html.erb @@ -8,7 +8,7 @@ Queue 2000
  • Menu Items
  • - <%= link_to t('.new', :default => t("helpers.links.new")),new_settings_menu_category_menu_item_path(@category),:class => 'btn btn-primary btn-sm' %> + <%= link_to t('.new', :default => t("helpers.links.new")),new_settings_menu_category_simple_menu_item_path(@category),:class => 'btn btn-primary btn-sm' %> @@ -40,7 +40,13 @@
    -

    Menu Items

    +

    Menu Items + + <%= link_to "New Simple Menu Item",new_settings_menu_category_simple_menu_item_path(@category),:class => 'btn btn-primary btn-sm' %> + <%= link_to "New Set Menu Item",new_settings_menu_category_set_menu_item_path(@category),:class => 'btn btn-primary btn-sm' %> + +

    +

    <%= @settings_menu_items.count %>

    @@ -67,9 +73,9 @@ - - - + + + <% end %> diff --git a/app/views/settings/simple_menu_items/show.html.erb b/app/views/settings/simple_menu_items/show.html.erb index 66ae3e84..f69c83d4 100644 --- a/app/views/settings/simple_menu_items/show.html.erb +++ b/app/views/settings/simple_menu_items/show.html.erb @@ -36,13 +36,13 @@ - - - + + + - +
    <%= settings_menu_item.created_by %> <%=l settings_menu_item.created_at, :format => :short %><%= link_to 'Show', settings_menu_category_menu_item_path(@category, settings_menu_item ) %><%= link_to 'Edit', edit_settings_menu_category_menu_item_path(@category, settings_menu_item) %><%= link_to 'Destroy', settings_menu_category_menu_item_path(@category, settings_menu_item ), method: :delete, data: { confirm: 'Are you sure?' } %><%= link_to 'Show', settings_menu_category_simple_menu_item_path(@category, settings_menu_item ) %><%= link_to 'Edit', edit_settings_menu_category_simple_menu_item_path(@category, settings_menu_item) %><%= link_to 'Destroy', settings_menu_category_simple_menu_item_path(@category, settings_menu_item ), method: :delete, data: { confirm: 'Are you sure?' } %>
    <%= @settings_menu_item.name rescue "-" %> <%= @settings_menu_item.alt_name %> <%= @settings_menu_item.type %><%= @settings_menu_item.menu_category %><%= @settings_menu_item.menu_item %><%= @settings_menu_item.menu_qty %><%= @settings_menu_item.menu_category_id %><%= @settings_menu_item.menu_item_id %><%= @settings_menu_item.min_qty %> <%= @settings_menu_item.min_selectable_item %> <%= @settings_menu_item.max_selectable_item %> <%=l @settings_menu_item.created_at, format: :short %><%= link_to 'Edit', edit_settings_menu_menu_item_path(@settings_menu_category, @settings_menu_category) %><%= link_to 'Edit', edit_settings_menu_category_simple_menu_item_path(@category, @settings_menu_item) %>
    diff --git a/app/views/transactions/sales/_form.html.erb b/app/views/transactions/sales/_form.html.erb new file mode 100644 index 00000000..e83e3202 --- /dev/null +++ b/app/views/transactions/sales/_form.html.erb @@ -0,0 +1,27 @@ +<%= simple_form_for(@transactions_sale) do |f| %> + <%= f.error_notification %> + +
    + <%= f.association :cashier %> + <%= f.input :cashier_name %> + <%= f.input :requested_by %> + <%= f.input :requested_at %> + <%= f.input :receipt_no %> + <%= f.input :receipt_date %> + <%= f.association :customer %> + <%= f.input :payment_status %> + <%= f.input :sale_status %> + <%= f.input :total_amount %> + <%= f.input :total_discount %> + <%= f.input :total_tax %> + <%= f.input :tax_type %> + <%= f.input :grand_total %> + <%= f.input :rounding_adjustment %> + <%= f.input :amount_received %> + <%= f.input :amount_changed %> +
    + +
    + <%= f.button :submit %> +
    +<% end %> diff --git a/app/views/transactions/sales/_transactions_sale.json.jbuilder b/app/views/transactions/sales/_transactions_sale.json.jbuilder new file mode 100644 index 00000000..869b3cf7 --- /dev/null +++ b/app/views/transactions/sales/_transactions_sale.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! transactions_sale, :id, :cashier_id, :cashier_name, :requested_by, :requested_at, :receipt_no, :receipt_date, :customer_id, :payment_status, :sale_status, :total_amount, :total_discount, :total_tax, :tax_type, :grand_total, :rounding_adjustment, :amount_received, :amount_changed, :created_at, :updated_at +json.url transactions_sale_url(transactions_sale, format: :json) diff --git a/app/views/transactions/sales/edit.html.erb b/app/views/transactions/sales/edit.html.erb new file mode 100644 index 00000000..cf11644b --- /dev/null +++ b/app/views/transactions/sales/edit.html.erb @@ -0,0 +1,6 @@ +

    Editing Transactions Sale

    + +<%= render 'form', transactions_sale: @transactions_sale %> + +<%= link_to 'Show', @transactions_sale %> | +<%= link_to 'Back', transactions_sales_path %> diff --git a/app/views/transactions/sales/index.html.erb b/app/views/transactions/sales/index.html.erb new file mode 100644 index 00000000..c39b0ac3 --- /dev/null +++ b/app/views/transactions/sales/index.html.erb @@ -0,0 +1,59 @@ +

    <%= notice %>

    + +

    Transactions Sales

    + + + + + + + + + + + + + + + + + + + + + + + + + + + <% @transactions_sales.each do |transactions_sale| %> + + + + + + + + + + + + + + + + + + + + + + + <% end %> + +
    CashierCashier nameRequested byRequested atReceipt noReceipt dateCustomerPayment statusSale statusTotal amountTotal discountTotal taxTax typeGrand totalRounding adjustmentAmount receivedAmount changed
    <%= transactions_sale.cashier %><%= transactions_sale.cashier_name %><%= transactions_sale.requested_by %><%= transactions_sale.requested_at %><%= transactions_sale.receipt_no %><%= transactions_sale.receipt_date %><%= transactions_sale.customer %><%= transactions_sale.payment_status %><%= transactions_sale.sale_status %><%= transactions_sale.total_amount %><%= transactions_sale.total_discount %><%= transactions_sale.total_tax %><%= transactions_sale.tax_type %><%= transactions_sale.grand_total %><%= transactions_sale.rounding_adjustment %><%= transactions_sale.amount_received %><%= transactions_sale.amount_changed %><%= link_to 'Show', transactions_sale %><%= link_to 'Edit', edit_transactions_sale_path(transactions_sale) %><%= link_to 'Destroy', transactions_sale, method: :delete, data: { confirm: 'Are you sure?' } %>
    + +
    + +<%= link_to 'New Transactions Sale', new_transactions_sale_path %> diff --git a/app/views/transactions/sales/index.json.jbuilder b/app/views/transactions/sales/index.json.jbuilder new file mode 100644 index 00000000..a67adc38 --- /dev/null +++ b/app/views/transactions/sales/index.json.jbuilder @@ -0,0 +1 @@ +json.array! @transactions_sales, partial: 'transactions_sales/transactions_sale', as: :transactions_sale diff --git a/app/views/transactions/sales/new.html.erb b/app/views/transactions/sales/new.html.erb new file mode 100644 index 00000000..1f479747 --- /dev/null +++ b/app/views/transactions/sales/new.html.erb @@ -0,0 +1,5 @@ +

    New Transactions Sale

    + +<%= render 'form', transactions_sale: @transactions_sale %> + +<%= link_to 'Back', transactions_sales_path %> diff --git a/app/views/transactions/sales/show.html.erb b/app/views/transactions/sales/show.html.erb new file mode 100644 index 00000000..c82c2c5e --- /dev/null +++ b/app/views/transactions/sales/show.html.erb @@ -0,0 +1,89 @@ +

    <%= notice %>

    + +

    + Cashier: + <%= @transactions_sale.cashier %> +

    + +

    + Cashier name: + <%= @transactions_sale.cashier_name %> +

    + +

    + Requested by: + <%= @transactions_sale.requested_by %> +

    + +

    + Requested at: + <%= @transactions_sale.requested_at %> +

    + +

    + Receipt no: + <%= @transactions_sale.receipt_no %> +

    + +

    + Receipt date: + <%= @transactions_sale.receipt_date %> +

    + +

    + Customer: + <%= @transactions_sale.customer %> +

    + +

    + Payment status: + <%= @transactions_sale.payment_status %> +

    + +

    + Sale status: + <%= @transactions_sale.sale_status %> +

    + +

    + Total amount: + <%= @transactions_sale.total_amount %> +

    + +

    + Total discount: + <%= @transactions_sale.total_discount %> +

    + +

    + Total tax: + <%= @transactions_sale.total_tax %> +

    + +

    + Tax type: + <%= @transactions_sale.tax_type %> +

    + +

    + Grand total: + <%= @transactions_sale.grand_total %> +

    + +

    + Rounding adjustment: + <%= @transactions_sale.rounding_adjustment %> +

    + +

    + Amount received: + <%= @transactions_sale.amount_received %> +

    + +

    + Amount changed: + <%= @transactions_sale.amount_changed %> +

    + +<%= link_to 'Edit', edit_transactions_sale_path(@transactions_sale) %> | +<%= link_to 'Back', transactions_sales_path %> diff --git a/app/views/transactions/sales/show.json.jbuilder b/app/views/transactions/sales/show.json.jbuilder new file mode 100644 index 00000000..48c70528 --- /dev/null +++ b/app/views/transactions/sales/show.json.jbuilder @@ -0,0 +1 @@ +json.partial! "transactions_sales/transactions_sale", transactions_sale: @transactions_sale diff --git a/config/environments/development.rb b/config/environments/development.rb index 6f719704..f5ab7304 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -51,4 +51,7 @@ Rails.application.configure do # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker + + # Set Cable URL + config.action_cable.url = "ws://192.168.1.140:3002/cable" end diff --git a/config/routes.rb b/config/routes.rb index ed2cdab0..7b9dd91d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -5,6 +5,9 @@ Rails.application.routes.draw do root 'home#index' mount Sidekiq::Web => '/kiq' + # Action Cable Creation + mount ActionCable.server => "/cable" + #--------- SmartSales Installation ------------# get 'install' => 'install#index' post 'install' => 'install#create' @@ -142,7 +145,12 @@ Rails.application.routes.draw do end end + #--------- Transactions Sections ------------# + namespace :transactions do + resources :sales + end + #--------- Reports Controller Sections ------------# namespace :reports do resources :sales, :only => [:index, :show] resources :orders, :only => [:index, :show] diff --git a/db/migrate/20170403162221_create_sale_discounts.rb b/db/migrate/20170403162221_create_sale_discounts.rb deleted file mode 100644 index e10b2f98..00000000 --- a/db/migrate/20170403162221_create_sale_discounts.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateSaleDiscounts < ActiveRecord::Migration[5.0] - def change - create_table :sale_discounts do |t| - t.references :sale, foreign_key: true - t.string :discount_type, :null => false - t.decimal :discount_value, :precision => 10, :scale => 2, :null => false, :default => 0.00 - t.decimal :discount_amount, :precision => 10, :scale => 2, :null => false, :default => 0.00 - t.string :discount_code - - t.timestamps - end - end -end diff --git a/db/scaffold_structure b/db/scaffold_structure index 7446c21b..064f62d4 100644 --- a/db/scaffold_structure +++ b/db/scaffold_structure @@ -20,3 +20,5 @@ rails generate scaffold Setup/TaxProfile name:string rate:decimal inclusive:bool rails generate scaffold_controller Setup/CashierTerminal name:string is_active:boolean is_currently_login:boolean auto_print_receipt:string printer_name:string header:json footer:json font:string font_size:string show_tax:boolean show_cashier:boolean show_guest_info:boolean --no-migration rails generate scaffold_controller Settings/OrderQueueStation station_name:string is_active:boolean processing_items:json print_copy:boolean printer_name:string font_size:integer cut_per_item:boolean use_alternate_name:boolean created_by:string --no-migration + +rails generate scaffold_controller transactions/Sale cashier:references cashier_name:string requested_by:string requested_at:datetime receipt_no:string receipt_date:datetime customer:references payment_status:string sale_status:string total_amount:decimal total_discount:decimal total_tax:decimal tax_type:string grand_total:decimal rounding_adjustment:decimal amount_received:decimal amount_changed:decimal --no-migration diff --git a/dump.rdb b/dump.rdb index 96c96478..b931754d 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/redis-stable.tar.gz b/redis-stable.tar.gz new file mode 100644 index 00000000..47c49f3b Binary files /dev/null and b/redis-stable.tar.gz differ diff --git a/spec/controllers/transactions/sales_controller_spec.rb b/spec/controllers/transactions/sales_controller_spec.rb new file mode 100644 index 00000000..054e2430 --- /dev/null +++ b/spec/controllers/transactions/sales_controller_spec.rb @@ -0,0 +1,141 @@ +require 'rails_helper' + +# This spec was generated by rspec-rails when you ran the scaffold generator. +# It demonstrates how one might use RSpec to specify the controller code that +# was generated by Rails when you ran the scaffold generator. +# +# It assumes that the implementation code is generated by the rails scaffold +# generator. If you are using any extension libraries to generate different +# controller code, this generated spec may or may not pass. +# +# It only uses APIs available in rails and/or rspec-rails. There are a number +# of tools you can use to make these specs even more expressive, but we're +# sticking to rails and rspec-rails APIs to keep things simple and stable. +# +# Compared to earlier versions of this generator, there is very limited use of +# stubs and message expectations in this spec. Stubs are only used when there +# is no simpler way to get a handle on the object needed for the example. +# Message expectations are only used when there is no simpler way to specify +# that an instance is receiving a specific message. +# +# Also compared to earlier versions of this generator, there are no longer any +# expectations of assigns and templates rendered. These features have been +# removed from Rails core in Rails 5, but can be added back in via the +# `rails-controller-testing` gem. + +RSpec.describe Transactions::SalesController, type: :controller do + + # This should return the minimal set of attributes required to create a valid + # Transactions::Sale. As you add validations to Transactions::Sale, be sure to + # adjust the attributes here as well. + let(:valid_attributes) { + skip("Add a hash of attributes valid for your model") + } + + let(:invalid_attributes) { + skip("Add a hash of attributes invalid for your model") + } + + # This should return the minimal set of values that should be in the session + # in order to pass any filters (e.g. authentication) defined in + # Transactions::SalesController. Be sure to keep this updated too. + let(:valid_session) { {} } + + describe "GET #index" do + it "returns a success response" do + sale = Transactions::Sale.create! valid_attributes + get :index, params: {}, session: valid_session + expect(response).to be_success + end + end + + describe "GET #show" do + it "returns a success response" do + sale = Transactions::Sale.create! valid_attributes + get :show, params: {id: sale.to_param}, session: valid_session + expect(response).to be_success + end + end + + describe "GET #new" do + it "returns a success response" do + get :new, params: {}, session: valid_session + expect(response).to be_success + end + end + + describe "GET #edit" do + it "returns a success response" do + sale = Transactions::Sale.create! valid_attributes + get :edit, params: {id: sale.to_param}, session: valid_session + expect(response).to be_success + end + end + + describe "POST #create" do + context "with valid params" do + it "creates a new Transactions::Sale" do + expect { + post :create, params: {transactions_sale: valid_attributes}, session: valid_session + }.to change(Transactions::Sale, :count).by(1) + end + + it "redirects to the created transactions_sale" do + post :create, params: {transactions_sale: valid_attributes}, session: valid_session + expect(response).to redirect_to(Transactions::Sale.last) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'new' template)" do + post :create, params: {transactions_sale: invalid_attributes}, session: valid_session + expect(response).to be_success + end + end + end + + describe "PUT #update" do + context "with valid params" do + let(:new_attributes) { + skip("Add a hash of attributes valid for your model") + } + + it "updates the requested transactions_sale" do + sale = Transactions::Sale.create! valid_attributes + put :update, params: {id: sale.to_param, transactions_sale: new_attributes}, session: valid_session + sale.reload + skip("Add assertions for updated state") + end + + it "redirects to the transactions_sale" do + sale = Transactions::Sale.create! valid_attributes + put :update, params: {id: sale.to_param, transactions_sale: valid_attributes}, session: valid_session + expect(response).to redirect_to(sale) + end + end + + context "with invalid params" do + it "returns a success response (i.e. to display the 'edit' template)" do + sale = Transactions::Sale.create! valid_attributes + put :update, params: {id: sale.to_param, transactions_sale: invalid_attributes}, session: valid_session + expect(response).to be_success + end + end + end + + describe "DELETE #destroy" do + it "destroys the requested transactions_sale" do + sale = Transactions::Sale.create! valid_attributes + expect { + delete :destroy, params: {id: sale.to_param}, session: valid_session + }.to change(Transactions::Sale, :count).by(-1) + end + + it "redirects to the transactions_sales list" do + sale = Transactions::Sale.create! valid_attributes + delete :destroy, params: {id: sale.to_param}, session: valid_session + expect(response).to redirect_to(transactions_sales_url) + end + end + +end diff --git a/spec/helpers/transactions/sales_helper_spec.rb b/spec/helpers/transactions/sales_helper_spec.rb new file mode 100644 index 00000000..fd45fe62 --- /dev/null +++ b/spec/helpers/transactions/sales_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Transactions::SalesHelper. For example: +# +# describe Transactions::SalesHelper 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 Transactions::SalesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/models/order_queue_item_spec.rb b/spec/jobs/order_broadcast_job_spec.rb similarity index 63% rename from spec/models/order_queue_item_spec.rb rename to spec/jobs/order_broadcast_job_spec.rb index d4b7ed66..74f8f77c 100644 --- a/spec/models/order_queue_item_spec.rb +++ b/spec/jobs/order_broadcast_job_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe OrderQueueItem, type: :model do +RSpec.describe OrderBroadcastJob, type: :job do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/sale_discount_spec.rb b/spec/models/test_spec.rb similarity index 65% rename from spec/models/sale_discount_spec.rb rename to spec/models/test_spec.rb index 1365ceff..2b626b06 100644 --- a/spec/models/sale_discount_spec.rb +++ b/spec/models/test_spec.rb @@ -1,5 +1,5 @@ require 'rails_helper' -RSpec.describe SaleDiscount, type: :model do +RSpec.describe Test, type: :model do pending "add some examples to (or delete) #{__FILE__}" end diff --git a/spec/models/transactions/sale_spec.rb b/spec/models/transactions/sale_spec.rb new file mode 100644 index 00000000..8a24dfc4 --- /dev/null +++ b/spec/models/transactions/sale_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Transactions::Sale, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/requests/transactions/transactions_sales_spec.rb b/spec/requests/transactions/transactions_sales_spec.rb new file mode 100644 index 00000000..23ed6d80 --- /dev/null +++ b/spec/requests/transactions/transactions_sales_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +RSpec.describe "Transactions::Sales", type: :request do + describe "GET /transactions_sales" do + it "works! (now write some real specs)" do + get transactions_sales_path + expect(response).to have_http_status(200) + end + end +end diff --git a/spec/routing/transactions/sales_routing_spec.rb b/spec/routing/transactions/sales_routing_spec.rb new file mode 100644 index 00000000..e81109a2 --- /dev/null +++ b/spec/routing/transactions/sales_routing_spec.rb @@ -0,0 +1,39 @@ +require "rails_helper" + +RSpec.describe Transactions::SalesController, type: :routing do + describe "routing" do + + it "routes to #index" do + expect(:get => "/transactions/sales").to route_to("transactions/sales#index") + end + + it "routes to #new" do + expect(:get => "/transactions/sales/new").to route_to("transactions/sales#new") + end + + it "routes to #show" do + expect(:get => "/transactions/sales/1").to route_to("transactions/sales#show", :id => "1") + end + + it "routes to #edit" do + expect(:get => "/transactions/sales/1/edit").to route_to("transactions/sales#edit", :id => "1") + end + + it "routes to #create" do + expect(:post => "/transactions/sales").to route_to("transactions/sales#create") + end + + it "routes to #update via PUT" do + expect(:put => "/transactions/sales/1").to route_to("transactions/sales#update", :id => "1") + end + + it "routes to #update via PATCH" do + expect(:patch => "/transactions/sales/1").to route_to("transactions/sales#update", :id => "1") + end + + it "routes to #destroy" do + expect(:delete => "/transactions/sales/1").to route_to("transactions/sales#destroy", :id => "1") + end + + end +end diff --git a/spec/views/transactions/sales/edit.html.erb_spec.rb b/spec/views/transactions/sales/edit.html.erb_spec.rb new file mode 100644 index 00000000..8ab20cd0 --- /dev/null +++ b/spec/views/transactions/sales/edit.html.erb_spec.rb @@ -0,0 +1,60 @@ +require 'rails_helper' + +RSpec.describe "transactions/sales/edit", type: :view do + before(:each) do + @transactions_sale = assign(:transactions_sale, Transactions::Sale.create!( + :cashier => nil, + :cashier_name => "MyString", + :requested_by => "MyString", + :receipt_no => "MyString", + :customer => nil, + :payment_status => "MyString", + :sale_status => "MyString", + :total_amount => "9.99", + :total_discount => "9.99", + :total_tax => "9.99", + :tax_type => "MyString", + :grand_total => "9.99", + :rounding_adjustment => "9.99", + :amount_received => "9.99", + :amount_changed => "9.99" + )) + end + + it "renders the edit transactions_sale form" do + render + + assert_select "form[action=?][method=?]", transactions_sale_path(@transactions_sale), "post" do + + assert_select "input[name=?]", "transactions_sale[cashier_id]" + + assert_select "input[name=?]", "transactions_sale[cashier_name]" + + assert_select "input[name=?]", "transactions_sale[requested_by]" + + assert_select "input[name=?]", "transactions_sale[receipt_no]" + + assert_select "input[name=?]", "transactions_sale[customer_id]" + + assert_select "input[name=?]", "transactions_sale[payment_status]" + + assert_select "input[name=?]", "transactions_sale[sale_status]" + + assert_select "input[name=?]", "transactions_sale[total_amount]" + + assert_select "input[name=?]", "transactions_sale[total_discount]" + + assert_select "input[name=?]", "transactions_sale[total_tax]" + + assert_select "input[name=?]", "transactions_sale[tax_type]" + + assert_select "input[name=?]", "transactions_sale[grand_total]" + + assert_select "input[name=?]", "transactions_sale[rounding_adjustment]" + + assert_select "input[name=?]", "transactions_sale[amount_received]" + + assert_select "input[name=?]", "transactions_sale[amount_changed]" + end + end +end diff --git a/spec/views/transactions/sales/index.html.erb_spec.rb b/spec/views/transactions/sales/index.html.erb_spec.rb new file mode 100644 index 00000000..9071ef3a --- /dev/null +++ b/spec/views/transactions/sales/index.html.erb_spec.rb @@ -0,0 +1,61 @@ +require 'rails_helper' + +RSpec.describe "transactions/sales/index", type: :view do + before(:each) do + assign(:transactions_sales, [ + Transactions::Sale.create!( + :cashier => nil, + :cashier_name => "Cashier Name", + :requested_by => "Requested By", + :receipt_no => "Receipt No", + :customer => nil, + :payment_status => "Payment Status", + :sale_status => "Sale Status", + :total_amount => "9.99", + :total_discount => "9.99", + :total_tax => "9.99", + :tax_type => "Tax Type", + :grand_total => "9.99", + :rounding_adjustment => "9.99", + :amount_received => "9.99", + :amount_changed => "9.99" + ), + Transactions::Sale.create!( + :cashier => nil, + :cashier_name => "Cashier Name", + :requested_by => "Requested By", + :receipt_no => "Receipt No", + :customer => nil, + :payment_status => "Payment Status", + :sale_status => "Sale Status", + :total_amount => "9.99", + :total_discount => "9.99", + :total_tax => "9.99", + :tax_type => "Tax Type", + :grand_total => "9.99", + :rounding_adjustment => "9.99", + :amount_received => "9.99", + :amount_changed => "9.99" + ) + ]) + end + + it "renders a list of transactions/sales" do + render + assert_select "tr>td", :text => nil.to_s, :count => 2 + assert_select "tr>td", :text => "Cashier Name".to_s, :count => 2 + assert_select "tr>td", :text => "Requested By".to_s, :count => 2 + assert_select "tr>td", :text => "Receipt No".to_s, :count => 2 + assert_select "tr>td", :text => nil.to_s, :count => 2 + assert_select "tr>td", :text => "Payment Status".to_s, :count => 2 + assert_select "tr>td", :text => "Sale Status".to_s, :count => 2 + assert_select "tr>td", :text => "9.99".to_s, :count => 2 + assert_select "tr>td", :text => "9.99".to_s, :count => 2 + assert_select "tr>td", :text => "9.99".to_s, :count => 2 + assert_select "tr>td", :text => "Tax Type".to_s, :count => 2 + assert_select "tr>td", :text => "9.99".to_s, :count => 2 + assert_select "tr>td", :text => "9.99".to_s, :count => 2 + assert_select "tr>td", :text => "9.99".to_s, :count => 2 + assert_select "tr>td", :text => "9.99".to_s, :count => 2 + end +end diff --git a/spec/views/transactions/sales/new.html.erb_spec.rb b/spec/views/transactions/sales/new.html.erb_spec.rb new file mode 100644 index 00000000..5e499ef5 --- /dev/null +++ b/spec/views/transactions/sales/new.html.erb_spec.rb @@ -0,0 +1,60 @@ +require 'rails_helper' + +RSpec.describe "transactions/sales/new", type: :view do + before(:each) do + assign(:transactions_sale, Transactions::Sale.new( + :cashier => nil, + :cashier_name => "MyString", + :requested_by => "MyString", + :receipt_no => "MyString", + :customer => nil, + :payment_status => "MyString", + :sale_status => "MyString", + :total_amount => "9.99", + :total_discount => "9.99", + :total_tax => "9.99", + :tax_type => "MyString", + :grand_total => "9.99", + :rounding_adjustment => "9.99", + :amount_received => "9.99", + :amount_changed => "9.99" + )) + end + + it "renders new transactions_sale form" do + render + + assert_select "form[action=?][method=?]", transactions_sales_path, "post" do + + assert_select "input[name=?]", "transactions_sale[cashier_id]" + + assert_select "input[name=?]", "transactions_sale[cashier_name]" + + assert_select "input[name=?]", "transactions_sale[requested_by]" + + assert_select "input[name=?]", "transactions_sale[receipt_no]" + + assert_select "input[name=?]", "transactions_sale[customer_id]" + + assert_select "input[name=?]", "transactions_sale[payment_status]" + + assert_select "input[name=?]", "transactions_sale[sale_status]" + + assert_select "input[name=?]", "transactions_sale[total_amount]" + + assert_select "input[name=?]", "transactions_sale[total_discount]" + + assert_select "input[name=?]", "transactions_sale[total_tax]" + + assert_select "input[name=?]", "transactions_sale[tax_type]" + + assert_select "input[name=?]", "transactions_sale[grand_total]" + + assert_select "input[name=?]", "transactions_sale[rounding_adjustment]" + + assert_select "input[name=?]", "transactions_sale[amount_received]" + + assert_select "input[name=?]", "transactions_sale[amount_changed]" + end + end +end diff --git a/spec/views/transactions/sales/show.html.erb_spec.rb b/spec/views/transactions/sales/show.html.erb_spec.rb new file mode 100644 index 00000000..6d2ec4cc --- /dev/null +++ b/spec/views/transactions/sales/show.html.erb_spec.rb @@ -0,0 +1,42 @@ +require 'rails_helper' + +RSpec.describe "transactions/sales/show", type: :view do + before(:each) do + @transactions_sale = assign(:transactions_sale, Transactions::Sale.create!( + :cashier => nil, + :cashier_name => "Cashier Name", + :requested_by => "Requested By", + :receipt_no => "Receipt No", + :customer => nil, + :payment_status => "Payment Status", + :sale_status => "Sale Status", + :total_amount => "9.99", + :total_discount => "9.99", + :total_tax => "9.99", + :tax_type => "Tax Type", + :grand_total => "9.99", + :rounding_adjustment => "9.99", + :amount_received => "9.99", + :amount_changed => "9.99" + )) + end + + it "renders attributes in

    " do + render + expect(rendered).to match(//) + expect(rendered).to match(/Cashier Name/) + expect(rendered).to match(/Requested By/) + expect(rendered).to match(/Receipt No/) + expect(rendered).to match(//) + expect(rendered).to match(/Payment Status/) + expect(rendered).to match(/Sale Status/) + expect(rendered).to match(/9.99/) + expect(rendered).to match(/9.99/) + expect(rendered).to match(/9.99/) + expect(rendered).to match(/Tax Type/) + expect(rendered).to match(/9.99/) + expect(rendered).to match(/9.99/) + expect(rendered).to match(/9.99/) + expect(rendered).to match(/9.99/) + end +end diff --git a/test/application_system_test_case.rb b/test/application_system_test_case.rb new file mode 100644 index 00000000..d19212ab --- /dev/null +++ b/test/application_system_test_case.rb @@ -0,0 +1,5 @@ +require "test_helper" + +class ApplicationSystemTestCase < ActionDispatch::SystemTestCase + driven_by :selenium, using: :chrome, screen_size: [1400, 1400] +end diff --git a/test/system/sales_test.rb b/test/system/sales_test.rb new file mode 100644 index 00000000..7df56114 --- /dev/null +++ b/test/system/sales_test.rb @@ -0,0 +1,9 @@ +require "application_system_test_case" + +class Transactions::SalesTest < ApplicationSystemTestCase + # test "visiting the index" do + # visit transactions_sales_url + # + # assert_selector "h1", text: "Transactions::Sale" + # end +end