diff --git a/.gitignore b/.gitignore index 9dde67bb..02338531 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,7 @@ config/deploy/config/* # Ignore Byebug command history file. .byebug_history + +# Gem files +#Gemfile +#Gemfile.lock diff --git a/Gemfile b/Gemfile index 5fd85f3f..0b7c3f11 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 'mysql2', '>= 0.3.18', '< 0.5' + 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 a9c1f0fc..5dce67dc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://github.com/amatsuda/kaminari.git - revision: bc52ae73d41386d344b5d1b18e689e5a988f1a03 + revision: c3c853a944cd2bff072ae05e48c563b2c9a29597 branch: master specs: kaminari (1.0.1) @@ -66,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 @@ -114,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) @@ -251,6 +252,7 @@ DEPENDENCIES jquery-rails kaminari! listen (~> 3.0.5) + mysql2 (>= 0.3.18, < 0.5) pg prawn prawn-table @@ -274,4 +276,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..80a09b47 100644 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -15,3 +15,69 @@ //= require jquery_ujs //= require turbolinks //= require cable + +$(document).ready(function(){ + $('.queue_station').on('click',function(){ + var orderZone=$(this).children().children().children('.order-zone').text(); + var orderItem=$(this).children().children().children('.order-item').text(); + var orderQty=$(this).children().children().children('.order-qty').text(); + 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 DETAILS - " + orderZone); + $('#order-by').text(orderBy); + $('#order-at').text(orderAt); + $('#order-customer').text(orderCustomer); + $('#order-from').text(orderZone); + + $('#order-items').text(orderItem); + $('#order-qty').text(orderQty); + + $('.queue_station').removeClass('selected-item'); + $(this).addClass('selected-item'); + }); + + // complete for queue item + $('.order-complete').on('click',function(){ + var _self= $(this); + var assigned_item_id=$(this).attr('id').substr(15); + var params = { 'id':assigned_item_id }; + var station=$(this).parent().parent(".queue_station").parent().parent().attr('id'); + + $.ajax({ + type: 'POST', + url: '/oqs/update_delivery', + data: params, + dataType: 'json', + success: function(data){ + var queue_station=_self.parent().parent(".queue_station"); + + // Remove a queue card from current station + queue_station.remove(); + + // Remove a queue card from current station + queue_station.children('.card-footer').remove(); + + // Add removed queue card from station to completed + $("#completed").children('.card-columns').append(queue_station); + + // update queue item count in station + $("#"+station+"_count").text(parseInt($("#"+station+"_count").text())-1); + $("#completed_count").text(parseInt($("#completed_count").text())+1); + + alert("updated!"); + } + }); + }); + + $('#print_order_item').on('click',function(){ + var assigned_item_id=$('.selected-item').children('.card-block').children('.assigned-order-item').text(); + var params = { 'id':assigned_item_id }; + $.ajax({ + type: 'GET', + url: '/oqs/print/print/'+assigned_item_id, + success: function(data){ } + }); + }); +}); 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/origami/request_bills.coffee b/app/assets/javascripts/origami/request_bills.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/origami/request_bills.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/javascripts/print_settings.coffee b/app/assets/javascripts/print_settings.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/print_settings.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/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/OQS.scss b/app/assets/stylesheets/OQS.scss index 23a49d41..07c98b85 100644 --- a/app/assets/stylesheets/OQS.scss +++ b/app/assets/stylesheets/OQS.scss @@ -14,3 +14,7 @@ .order-void { background-color: #FFCCDD; } + +.selected-item { + background-color: blue; +} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 7aa6d6c5..9456be10 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -9,6 +9,29 @@ // padding-top: 4.5rem; // } +.setting_nav{ + background-color: #2f5663; +} + +ul.navbar-nav li a{ + text-decoration :none; + color :#e6e6e6; +} + +ul.dropdown-menu li a{ + text-decoration :none; + color :#525252; +} + +.setting_breadcrumb{ + background-color: transparent !important; + margin-bottom: 0px !important; +} +.page-header{ + border-bottom :0px solid #000 !important; + margin :0px !important; +} + /*----- Order Processing Items -----*/ .opi_ul { display:block; @@ -33,4 +56,4 @@ /*----- Header Bar -----*/ -/*----- Header Bar -----*/ \ No newline at end of file +/*----- Header Bar -----*/ diff --git a/app/assets/stylesheets/origami/request_bills.scss b/app/assets/stylesheets/origami/request_bills.scss new file mode 100644 index 00000000..20719090 --- /dev/null +++ b/app/assets/stylesheets/origami/request_bills.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the origami/RequestBills controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/print_settings.scss b/app/assets/stylesheets/print_settings.scss new file mode 100644 index 00000000..7dd1ef04 --- /dev/null +++ b/app/assets/stylesheets/print_settings.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the print_settings controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss index e69de29b..60451880 100644 --- a/app/assets/stylesheets/scaffolds.scss +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,84 @@ +body { + background-color: #fff; + color: #333; + margin: 33px; + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; +} + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; +} + +a { + color: #000; + + &:visited { + color: #666; + } + + &:hover { + color: #fff; + background-color: #000; + } +} + +th { + padding-bottom: 5px; +} + +td { + padding: 0 5px 7px; +} + +div { + &.field, &.actions { + margin-bottom: 10px; + } +} + +#notice { + color: green; +} + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; +} + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px 7px 0; + margin-bottom: 20px; + background-color: #f0f0f0; + + h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px -7px 0; + background-color: #c00; + color: #fff; + } + + ul li { + font-size: 12px; + list-style: square; + } +} + +label { + display: block; +} 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/bookings_controller.rb b/app/controllers/api/bookings_controller.rb index 8f10655f..401cd4a8 100644 --- a/app/controllers/api/bookings_controller.rb +++ b/app/controllers/api/bookings_controller.rb @@ -1,6 +1,5 @@ class Api::BookingsController < Api::ApiController - - + skip_before_action :authenticate #Show customer by ID def index @customer = Customer.find_by(params[:id]) diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index d0fe2a77..443a754b 100644 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -7,7 +7,10 @@ class Api::OrdersController < Api::ApiController order = Order.find(params[:order_id]) order.order_items end - + def get_order + order = Order.find(params[:order_id]) + order.order_items + end # Description # This API allow new order creation @@ -36,7 +39,8 @@ 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 = false + @order.new_booking = true @order.booking_id = params[:booking_id] end diff --git a/app/controllers/crm/bookings_controller.rb b/app/controllers/crm/bookings_controller.rb new file mode 100644 index 00000000..eeb19f75 --- /dev/null +++ b/app/controllers/crm/bookings_controller.rb @@ -0,0 +1,18 @@ +class Crm::BookingsController < ApplicationController + + def update_booking + booking = Booking.find(params[:booking_id]) + + + status = booking.update_attributes(booking_status: params[:type]) + + if status == true + render json: JSON.generate({:status => true ,:type => params[:type]}) + + else + render json: JSON.generate({:status => false, :error_message => "Record not found"}) + + end + end + +end diff --git a/app/controllers/crm/home_controller.rb b/app/controllers/crm/home_controller.rb index ee29270a..083f2bf7 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 + @customer = Customer.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.id as order_id, + # 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") + end def show end diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index acf99e41..1292a5e6 100644 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -1,6 +1,50 @@ class Oqs::HomeController < BaseOqsController def index + queue_stations=OrderQueueStation.all + + @queue_items_details = queue_items_query(0) + + @queue_completed_item = queue_items_query(1) + + @queue_stations_items=Array.new + + # Calculate Count for each station tab + queue_stations.each do |que| + i=0 + @queue_items_details.each do |qid| + if qid.station_name == que.station_name + i=i+1 + end + end + @queue_stations_items.push({:station_name => que.station_name, :is_active => que.is_active ,:item_count => i }) + end + + @queue_stations_items end + def show end + + # update delivery status when complete click + def update_delivery_status + assigned_item_id = params[:id] + assigned_item=AssignedOrderItem.find(assigned_item_id) + assigned_item.delivery_status=true + assigned_item.save + end + + # Query for OQS with status + def queue_items_query(status) + AssignedOrderItem.select("assigned_order_items.id, oqs.station_name, oqs.is_active, df.name as zone, odt.item_code, odt.item_name, odt.price, odt.qty, odt.item_order_by, cus.name as customer_name, odt.created_at") + .joins("join order_queue_process_by_zones as oqpz ON oqpz.order_queue_station_id = assigned_order_items.order_queue_station_id + left join dining_facilities as df on df.zone_id = oqpz.zone_id + left join order_queue_stations as oqs ON oqs.id = assigned_order_items.order_queue_station_id + left join orders as od ON od.id = assigned_order_items.order_id + left join order_items as odt ON odt.item_code = assigned_order_items.item_code + left join customers as cus ON cus.id = od.customer_id") + .where("assigned_order_items.delivery_status = #{status}") + .group("assigned_order_items.id") + .order("odt.item_name DESC") + end end + diff --git a/app/controllers/oqs/print_controller.rb b/app/controllers/oqs/print_controller.rb new file mode 100644 index 00000000..368a513d --- /dev/null +++ b/app/controllers/oqs/print_controller.rb @@ -0,0 +1,16 @@ +class Oqs::PrintController < ApplicationController + def print + unique_code="OrderItemPdf" + assigned_item_id=params[:id] + assigned_order_item=AssignedOrderItem.select("order_id, item_code").where('id='+assigned_item_id) + + print_settings=PrintSetting.find_by_unique_code(unique_code) + order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) + order_queue_printer.print_order_item(print_settings,assigned_order_item[0].order_id, assigned_order_item[0].item_code ) + + # update print status when complete click + assigned_item=AssignedOrderItem.find(assigned_item_id) + assigned_item.print_status=true + assigned_item.save + 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/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb new file mode 100644 index 00000000..9f971289 --- /dev/null +++ b/app/controllers/origami/request_bills_controller.rb @@ -0,0 +1,22 @@ +class Origami::RequestBillsController < BaseOrigamiController + def show + @sale = Sale.new + + check_order = Order.find_by_id(params[:id]) + if check_order + @order_details = OrderItem.get_order_items_details(check_order.id) + @order_details = OrderItem.get_order_items_details(check_order.id) + @status, @sale_id = @sale.generate_invoice_from_order(check_order.id, nil,current_login_employee.name) + @sale_data = Sale.find_by_id(@sale_id) + @sale_items = SaleItem.where("sale_id=?",@sale_id) + end + unique_code="ReceiptBillPdf" + print_settings=PrintSetting.find_by_unique_code(unique_code) + + printer = Printer::ReceiptPrinter.new(print_settings) + + printer.print_receipt_bill(print_settings,@sale_items,@sale) + + + end +end diff --git a/app/controllers/print_settings_controller.rb b/app/controllers/print_settings_controller.rb new file mode 100644 index 00000000..fa5af7e8 --- /dev/null +++ b/app/controllers/print_settings_controller.rb @@ -0,0 +1,74 @@ +class PrintSettingsController < ApplicationController + before_action :set_print_setting, only: [:show, :edit, :update, :destroy] + + # GET /print_settings + # GET /print_settings.json + def index + @print_settings = PrintSetting.all + end + + # GET /print_settings/1 + # GET /print_settings/1.json + def show + end + + # GET /print_settings/new + def new + @print_setting = PrintSetting.new + end + + # GET /print_settings/1/edit + def edit + end + + # POST /print_settings + # POST /print_settings.json + def create + @print_setting = PrintSetting.new(print_setting_params) + + respond_to do |format| + if @print_setting.save + format.html { redirect_to @print_setting, notice: 'Print setting was successfully created.' } + format.json { render :show, status: :created, location: @print_setting } + else + format.html { render :new } + format.json { render json: @print_setting.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /print_settings/1 + # PATCH/PUT /print_settings/1.json + def update + respond_to do |format| + if @print_setting.update(print_setting_params) + format.html { redirect_to @print_setting, notice: 'Print setting was successfully updated.' } + format.json { render :show, status: :ok, location: @print_setting } + else + format.html { render :edit } + format.json { render json: @print_setting.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /print_settings/1 + # DELETE /print_settings/1.json + def destroy + @print_setting.destroy + respond_to do |format| + format.html { redirect_to print_settings_url, notice: 'Print setting was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_print_setting + @print_setting = PrintSetting.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def print_setting_params + params.require(:print_setting).permit(:name, :unique_code, :template, :db_name, :db_type, :db_username, :db_password, :printer_name, :api_settings, :page_width, :page_height, :print_copies) + end +end diff --git a/app/controllers/settings/accounts_controller.rb b/app/controllers/settings/accounts_controller.rb new file mode 100644 index 00000000..74f27c84 --- /dev/null +++ b/app/controllers/settings/accounts_controller.rb @@ -0,0 +1,73 @@ +class Settings::AccountsController < ApplicationController + before_action :set_account, only: [:show, :edit, :update, :destroy] + + # GET /settings/accounts + # GET /settings/accounts.json + def index + @settings_accounts = Account.all + end + + # GET /settings/accounts/1 + # GET /settings/accounts/1.json + def show + end + + # GET /settings/accounts/new + def new + @settings_account = Account.new + end + + # GET /settings/accounts/1/edit + def edit + end + + # POST /settings/accounts + # POST /settings/accounts.json + def create + @settings_account = Account.new(account_params) + respond_to do |format| + if @settings_account.save! + format.html { redirect_to settings_accounts_url, notice: 'Account was successfully created.' } + format.json { render :index, status: :created, location: @settings_account } + else + format.html { render :new } + format.json { render json: settings_accounts_url.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /settings/accounts/1 + # PATCH/PUT /settings/accounts/1.json + def update + respond_to do |format| + if @settings_account.update(account_params) + format.html { redirect_to settings_accounts_url, notice: 'Account was successfully updated.' } + format.json { render :index, status: :ok, location: @settings_account } + else + format.html { render :edit } + format.json { render json: settings_accounts_url.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /settings/accounts/1 + # DELETE /settings/accounts/1.json + def destroy + @settings_account.destroy + respond_to do |format| + format.html { redirect_to settings_accounts_url, notice: 'Account was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_account + @settings_account = Account.find(params[:id]) + end + + # Never trust parameters from the scary internet, only allow the white list through. + def account_params + params.require(:account).permit(:title, :account_type) + end +end diff --git a/app/controllers/settings/menu_item_instances_controller.rb b/app/controllers/settings/menu_item_instances_controller.rb index 97115e4e..6bd00638 100644 --- a/app/controllers/settings/menu_item_instances_controller.rb +++ b/app/controllers/settings/menu_item_instances_controller.rb @@ -109,6 +109,8 @@ class Settings::MenuItemInstancesController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_menu_item_instance_params + params.require(:menu_item_instance).permit(:item_instance_code, :item_instance_name, :price, :item_attributes, :is_on_promotion, :promotion_price, :is_available,:menu_category_id,:menu_item_id) + end end diff --git a/app/controllers/settings/set_menu_items_controller.rb b/app/controllers/settings/set_menu_items_controller.rb index 7ef6cc18..f6771548 100644 --- a/app/controllers/settings/set_menu_items_controller.rb +++ b/app/controllers/settings/set_menu_items_controller.rb @@ -6,12 +6,14 @@ class Settings::SetMenuItemsController < ApplicationController def index @settings_menu_items = @category.menu_items.page(params[:page]).per(10) end - + # GET /settings/menu_items/1 # GET /settings/menu_items/1.json def show @sub_menu = MenuItem.where("menu_item_id=?",params[:id]).page(params[:page]).per(10) + @menu_item_instance = MenuItemInstance.where("menu_item_id=?",params[:id]).page(params[:page]).per(10) + end # GET /settings/menu_items/new diff --git a/app/controllers/settings/simple_menu_items_controller.rb b/app/controllers/settings/simple_menu_items_controller.rb index 08186297..e0d45fcb 100644 --- a/app/controllers/settings/simple_menu_items_controller.rb +++ b/app/controllers/settings/simple_menu_items_controller.rb @@ -6,7 +6,7 @@ class Settings::SimpleMenuItemsController < ApplicationController def index @settings_menu_items = @category.menu_items.page(params[:page]).per(10) end - + # GET /settings/menu_items/1 # GET /settings/menu_items/1.json def show 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/forms/shop_form.rb b/app/forms/shop_form.rb new file mode 100644 index 00000000..19af84a5 --- /dev/null +++ b/app/forms/shop_form.rb @@ -0,0 +1,7 @@ +#Form object to use during the installation process - will handle creation of shop model into db after verification from the cloud +#provising service through license verification + +class ShopForm < ActiveModel + :attr_accessor :logo, :name, :address, :township, :city, :state, :country, :license, :base_currency, :password, :password_confirmation + +end diff --git a/app/helpers/crm/bookings_helper.rb b/app/helpers/crm/bookings_helper.rb new file mode 100644 index 00000000..2d775cd1 --- /dev/null +++ b/app/helpers/crm/bookings_helper.rb @@ -0,0 +1,2 @@ +module Crm::BookingsHelper +end diff --git a/app/helpers/oqs/print_helper.rb b/app/helpers/oqs/print_helper.rb new file mode 100644 index 00000000..8deee2c2 --- /dev/null +++ b/app/helpers/oqs/print_helper.rb @@ -0,0 +1,2 @@ +module Oqs::PrintHelper +end diff --git a/app/helpers/origami/request_bills_helper.rb b/app/helpers/origami/request_bills_helper.rb new file mode 100644 index 00000000..a33f7c3e --- /dev/null +++ b/app/helpers/origami/request_bills_helper.rb @@ -0,0 +1,2 @@ +module Origami::RequestBillsHelper +end diff --git a/app/helpers/print_settings_helper.rb b/app/helpers/print_settings_helper.rb new file mode 100644 index 00000000..3e712d7c --- /dev/null +++ b/app/helpers/print_settings_helper.rb @@ -0,0 +1,2 @@ +module PrintSettingsHelper +end diff --git a/app/helpers/settings/accounts_helper.rb b/app/helpers/settings/accounts_helper.rb new file mode 100644 index 00000000..de8b6ad9 --- /dev/null +++ b/app/helpers/settings/accounts_helper.rb @@ -0,0 +1,2 @@ +module Settings::AccountsHelper +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..28a152ce --- /dev/null +++ b/app/jobs/order_broadcast_job.rb @@ -0,0 +1,9 @@ +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/account.rb b/app/models/account.rb new file mode 100644 index 00000000..e1cdc6d3 --- /dev/null +++ b/app/models/account.rb @@ -0,0 +1,7 @@ +class Account < ApplicationRecord + validates_presence_of :title, :account_type + + has_many :menu_items + # belongs_to :lookup , :class_name => "Lookup" + +end diff --git a/app/models/booking.rb b/app/models/booking.rb index c6a6452e..c34ecf42 100644 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -1,5 +1,6 @@ class Booking < ApplicationRecord - + #primary key - need to be unique + belongs_to :dining_facility, :optional => true belongs_to :sale, :optional => true has_many :booking_orders diff --git a/app/models/booking_order.rb b/app/models/booking_order.rb index c0883967..c9f748f0 100644 --- a/app/models/booking_order.rb +++ b/app/models/booking_order.rb @@ -1,4 +1,6 @@ class BookingOrder < ApplicationRecord + #primary key - need to be unique + belongs_to :booking belongs_to :order end diff --git a/app/models/crm.rb b/app/models/crm.rb new file mode 100644 index 00000000..3407e215 --- /dev/null +++ b/app/models/crm.rb @@ -0,0 +1,5 @@ +module Crm + def self.table_name_prefix + 'crm_' + end +end 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/lookup.rb b/app/models/lookup.rb index 1784b7a7..e1b141df 100644 --- a/app/models/lookup.rb +++ b/app/models/lookup.rb @@ -1,4 +1,6 @@ class Lookup < ApplicationRecord + + has_many :accounts def available_types {'Employee Roles' => 'employee_roles', diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index e84ce61e..2a4e86be 100644 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -1,12 +1,17 @@ class MenuItem < ApplicationRecord + belongs_to :account belongs_to :menu_category, :optional => true has_many :menu_item_instances belongs_to :parent, :class_name => "MenuItem", foreign_key: "menu_item_id", :optional => true has_many :children, :class_name => "MenuItem", foreign_key: "menu_item_id" - validates_presence_of :item_code, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item + + validates_presence_of :item_code, :name, :type, :min_qty, :taxable, :min_selectable_item, :max_selectable_item default_scope { order('item_code asc') } + scope :simple_menu_item, -> { where(type: 'SimpleMenuItem') } + scope :set_menu_item, -> { where(type: 'SetMenuItem') } + def self.collection MenuItem.select("id, name").map { |e| [e.name, e.id] } end diff --git a/app/models/order.rb b/app/models/order.rb index 0bec3a1e..f571faa9 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -1,4 +1,6 @@ class Order < ApplicationRecord + #primary key - need to be unique + before_create :set_order_date belongs_to :customer @@ -8,7 +10,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 : "", @@ -17,13 +18,14 @@ class Order < ApplicationRecord # option_values : [], # sub_order_items : [], # } + def generate 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 => "new" }) + :booking_status => "assign" }) else if (self.booking_id.to_i > 0 ) booking = Booking.find(self.booking_id) @@ -43,6 +45,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 @@ -201,4 +206,50 @@ class Order < ApplicationRecord #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,order_items.id,dining_facilities.name") + end + #Origami: Cashier : to view orders + def self.get_orders + from = Time.now.beginning_of_day.utc + to = Time.now.end_of_day.utc + 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=? and orders.date between ? and ?",true,from,to) + .group("orders.id") + end end diff --git a/app/models/order_item.rb b/app/models/order_item.rb index afba7d7e..1633c1c4 100644 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -1,4 +1,6 @@ class OrderItem < ApplicationRecord + #primary key - need to be unique + #Associations belongs_to :order, autosave: true @@ -32,5 +34,12 @@ class OrderItem < ApplicationRecord orderitem.save! + 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_item.rb b/app/models/order_queue_item.rb deleted file mode 100644 index 7f94fbec..00000000 --- a/app/models/order_queue_item.rb +++ /dev/null @@ -1,2 +0,0 @@ -class OrderQueueItem < ApplicationRecord -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/print_setting.rb b/app/models/print_setting.rb new file mode 100644 index 00000000..b715af52 --- /dev/null +++ b/app/models/print_setting.rb @@ -0,0 +1,2 @@ +class PrintSetting < ApplicationRecord +end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 4e520ed9..6a8a4b78 100644 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -1,22 +1,46 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker - def print_order_item(order_queue_id) + def print_order_item(printer_settings,order_id, item_code) #Use CUPS service #Generate PDF #Print - pdf = OrderItemPdf.new - pdf.render_file "tmp/order_item_queue_#{order_id}_#{order_item_id}" + ".pdf" + order_item= print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) + pdf = OrderItemPdf.new(order_item[0],printer_settings) + pdf.render_file "tmp/receipt.pdf" self.print("tmp/receipt.pdf") end - def print_order_summary(booking_id) + def print_order_summary(printer_settings,booking_id) #Use CUPS service #Generate PDF #Print + order=print_query('booking',booking_id) filename = "tmp/order_summary_#{booking_id}" + ".pdf" - pdf = OrderSummaryPdf.new + pdf = OrderSummaryPdf.new(order,printer_settings) pdf.render_file filename self.print(filename) end + + # Query for OQS with status + def print_query(type, code) + if type == 'order_item' + OrderItem.select("order_items.item_code, order_items.item_name,order_items.item_order_by as order_by, order_items.created_at as order_at, cus.name as customer, df.name as dining") + .joins("left join orders ON orders.id = order_items.order_id + left join booking_orders AS bo ON bo.order_id=order_items.order_id + left join bookings AS b ON b.id = bo.booking_id + left join dining_facilities AS df ON df.id = b.dining_facility_id + left join customers as cus ON cus.id = orders.customer_id") + .where("order_items.item_code=" + code) + .group("order_items.item_code") + else + OrderItem.select("order_items.item_code, order_items.item_name, df.name as dining") + .joins("left join orders ON orders.id = order_items.order_id + left join booking_orders AS bo ON bo.order_id=order_items.order_id + left join bookings AS b ON b.id = bo.booking_id + left join dining_facilities AS df ON df.id = b.dining_facility_id") + .where("booking.id=" + code) + end + + end end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 521b87e0..d25dc8c3 100644 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -63,4 +63,13 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker self.print(filename) end +#Bill Receipt Print + def print_receipt_bill(printer_settings,sale_items,sale) + #Use CUPS service + #Generate PDF + #Print + pdf = ReceiptBillPdf.new(printer_settings,sale_items,sale) + pdf.render_file "tmp/receipt_bill_#{sale.id}.pdf" + self.print("tmp/receipt_bill_#{sale.id}.pdf") + end end diff --git a/app/models/sale.rb b/app/models/sale.rb index 37819c9b..ca3bd631 100644 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -1,3 +1,5 @@ +#primary key - need to be unique generated for multiple shops + class Sale < ApplicationRecord #before_create :generate_receipt_no belongs_to :cashier, :optional => true @@ -188,7 +190,8 @@ class Sale < ApplicationRecord sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate #include or execulive - sale_tax.tax_payable_amount = total_taxable * tax.rate + # sale_tax.tax_payable_amount = total_taxable * tax.rate + sale_tax.tax_payable_amount = total_taxable * tax.rate / 100 #new taxable amount total_taxable = total_taxable + sale_tax.tax_payable_amount diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index 15fee460..cce6982d 100644 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -1,4 +1,6 @@ class SaleAudit < ApplicationRecord +#primary key - need to be unique generated for multiple shops + belongs_to :sale def record_audit_void(sale_id, void_by, approved_by, reason) 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/sale_item.rb b/app/models/sale_item.rb index 82b20237..c92ed48f 100644 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -1,4 +1,6 @@ class SaleItem < ApplicationRecord +#primary key - need to be unique generated for multiple shops + belongs_to :sale #compute items - discount, tax, price_change diff --git a/app/models/sale_order.rb b/app/models/sale_order.rb index 7a27f5a3..23fd39bd 100644 --- a/app/models/sale_order.rb +++ b/app/models/sale_order.rb @@ -1,4 +1,6 @@ class SaleOrder < ApplicationRecord +#primary key - need to be unique generated for multiple shops + belongs_to :sale belongs_to :order end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 71793f4c..2f7b72ea 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -1,4 +1,6 @@ class SalePayment < ApplicationRecord +#primary key - need to be unique generated for multiple shops + belongs_to :sale :attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status diff --git a/app/models/sale_tax.rb b/app/models/sale_tax.rb index cb3fae0b..6e0a2d47 100644 --- a/app/models/sale_tax.rb +++ b/app/models/sale_tax.rb @@ -1,3 +1,5 @@ class SaleTax < ApplicationRecord +#primary key - need to be unique generated for multiple shops + belongs_to :sale end diff --git a/app/models/seed_generator.rb b/app/models/seed_generator.rb index 573e0ff6..4351e74b 100644 --- a/app/models/seed_generator.rb +++ b/app/models/seed_generator.rb @@ -1,4 +1,23 @@ class SeedGenerator < ApplicationRecord + def self.generate_id(model, prefix) + seed = SeedGenerator.find_by_model(model) + new_receipt_no = 0 + if (seed.nil?) + seed = SeedGenerator.new() + seed.model = model + new_receipt_no = seed.next + seed.save + + else + current_no = seed.next + seed.next = seed.next + seed.increase_by + seed.current = current_no + seed.save + end + + return prefix + "-" + seed.current.to_s + end + def self.new_receipt_no seed = SeedGenerator.find_by_model("sale") new_receipt_no = 0 diff --git a/app/models/shop.rb b/app/models/shop.rb new file mode 100644 index 00000000..1cf1119c --- /dev/null +++ b/app/models/shop.rb @@ -0,0 +1,2 @@ +class Shop < ApplicationRecord +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/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 76df37e2..356327b4 100644 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -5,14 +5,27 @@ class OrderItemPdf < Prawn::Document # font "public/fonts/#{font_name}".to_s + ".ttf".to_s # font "public/fonts/Zawgyi-One.ttf" - # font "public/fonts/padauk.ttf" - - + # font "public/fonts/padauk.ttf" font_size 9 - text "#{"table_name"}", :size => 15 + text "#{order_item.dining}", :size => 15 stroke_horizontal_rule move_down 5 + cashier_info(order_item.order_by,order_item.order_at, order_item.customer) + + end + + def cashier_info(order_by, order_at, customer) + move_down 5 + y_position = cursor + + bounding_box([0,y_position], :width =>200, :height => 20) do + text "OrderBy:#{order_by} Customer:#{customer} Date:#{order_at.strftime("%Y %m %d")}", :size => 7,:align => :left + end + + stroke_horizontal_rule + + move_down 5 end end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb new file mode 100644 index 00000000..e9ad042c --- /dev/null +++ b/app/pdf/receipt_bill_pdf.rb @@ -0,0 +1,110 @@ +class ReceiptBillPdf < Prawn::Document + attr_accessor :receipt_width,:price_column_width,:p_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_column_width,:item_description_width + def initialize(printer_settings, sale_items,sale) + self.p_width = 200 + self.page_height = 1450 + self.margin = 10 + # self.price_width = self.p_width / 2 + self.price_width=90 + self.item_width = self.p_width - self.price_width + self.item_height = self.item_height + self.qty_column_width = self.p_width / 2 + self.item_description_width=self.p_width - self.price_width + self.receipt_width=130 + + @item_width = self.p_width.to_i / 2 + @qty_width = @item_width.to_i / 3 + @double = @qty_width * 2 + @half_qty = @qty_width / 2 + #setting page margin and width + super(:margin => [self.margin, self.margin, self.margin, self.margin], :page_size => [self.p_width, self.page_height]) + self.header_font_size = 10 + self.item_font_size = 6 + + header( printer_settings.printer_name, printer_settings.name) + stroke_horizontal_rule + cashier_info(sale.receipt_no,sale.customer.name, sale.receipt_date) + line_items(sale_items) + + + end + + def header (printer_name, name) + text "#{printer_name}", :size => self.header_font_size,:align => :center + move_down 5 + text "#{name}", :size => self.header_font_size,:align => :center + # move_down self.item_height + move_down 5 + + stroke_horizontal_rule + + end + + def cashier_info(receipt_no, customer, receipt_date) + move_down 5 + move_down 2 + y_position = cursor + bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + text "Receipt No:", :size => self.item_font_size,:align => :left + end + + bounding_box([self.price_width, y_position], :width =>self.receipt_width) do + text "#{receipt_no}" , :size => self.item_font_size, :align => :left + end + move_down 5 + + y_position = cursor + bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + text "Customer:", :size => self.item_font_size,:align => :left + end + bounding_box([self.price_width,y_position], :width =>self.price_width) do + text "#{customer}" , :size => self.item_font_size,:align => :left + end + move_down 5 + + y_position = cursor + bounding_box([0,y_position], :width =>self.price_width, :height => self.item_height) do + text "Date:", :size => self.item_font_size,:align => :left + end + bounding_box([self.price_width,y_position], :width =>self.price_width) do + text "#{receipt_date}" , :size => self.item_font_size,:align => :left + end + # stroke_horizontal_rule + move_down 5 + end + + def line_items(sale_items) + y_position = cursor + qty_column_width = self.p_width * 0.2 + item_description_width = self.p_width * 0.5 + price_column_width = self.p_width * 0.3 + + + + stroke_horizontal_rule + move_down 5 + y_position = cursor + pad_top(15) { + # @item_width.to_i + @half_qty.to_i + text_box "Items", :at =>[0,y_position], :width => @item_width.to_i - @half_qty.to_i , :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size + text_box "Price", :at =>[@item_width.to_i - @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right + text_box "Qty", :at =>[@item_width.to_i-@qty_width,y_position], :width => @half_qty, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right + text_box "Discount", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @qty_width, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right + text_box "Total", :at =>[@item_width.to_i + @half_qty.to_i,y_position], :width => @double, :height =>15, :overflow => :shrink_to_fix, :size => self.item_font_size, :align => :right + + } + + move_down 5 + stroke_horizontal_rule + + add_line_item_row(sale_items) + stroke_horizontal_rule + + end + + def add_line_item_row(sale_items) + y_position = cursor + move_down 5 + end + +end diff --git a/app/views/api/bookings/show.json.jbuilder b/app/views/api/bookings/show.json.jbuilder index d579810c..c4edb79f 100644 --- a/app/views/api/bookings/show.json.jbuilder +++ b/app/views/api/bookings/show.json.jbuilder @@ -2,6 +2,8 @@ if (@booking) json.id @booking.id json.status @booking.booking_status json.checkin_at @booking.checkin_at + json.checkin_by @booking.checkin_by + json.table_name @booking.dining_facility.name if @booking.type == "TableBooking" json.table_id @booking.dining_facility_id diff --git a/app/views/crm/home/_booking.html.erb b/app/views/crm/home/_booking.html.erb new file mode 100644 index 00000000..b8d2ba50 --- /dev/null +++ b/app/views/crm/home/_booking.html.erb @@ -0,0 +1,115 @@ + + +
+ + Order at <%= booking.checkin_at.strftime("%H,%m") %>, <%= booking.checkin_by %> + +
+Name : <%= customer.name %>
+Contact No : <%= customer.contact_no %>
+Email : <%= customer.email %>
+This card has supporting text below as a natural lead-in to additional content.
+Last updated 3 mins ago
++ + Order at <%= booking.checkin_at.strftime("%H,%m") %>, <%= booking.checkin_by %> + +
+