diff --git a/README.md b/README.md index b42782e7..ee8846a0 100755 --- a/README.md +++ b/README.md @@ -111,6 +111,35 @@ sudo cat /etc/sudoers ### cope and parse %superuser ALL=(ALL) NOPASSWD: ALL +<---- Extra Fields Script -----> +DROP TABLE IF EXISTS `display_images`; +CREATE TABLE `display_images` ( + `id` bigint(20) NOT NULL AUTO_INCREMENT, + `shop_id` int(11) DEFAULT NULL, + `image` blob, + `created_by` varchar(255) DEFAULT NULL, + `created_at` datetime NOT NULL, + `updated_at` datetime NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; + +ALTER TABLE customers +ADD COLUMN image_path VARCHAR(255); + +ALTER TABLE employees +ADD COLUMN image_path VARCHAR(255); + +ALTER TABLE commissioners +ADD COLUMN image_path VARCHAR(255); + +ALTER TABLE sales +ADD COLUMN equal_persons INT(11) after rebate_status; +<---- Extra Fields Script -----> +For CloseCashierCustomisePdf in lookups + *** change CloseCashierPdf to CloseCashierCustomisePdf + 1) settings/print_settings + 2) settings/lookups => { type:print_settings, name: CloseCashierCustomisePdf, value:1 } + * ToDo list 1. Migration diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index 35e08b4f..ec3db11f 100755 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -77,11 +77,19 @@ $(document).on('turbolinks:load', function() { }); } } - + + var table_type = ''; + if (data[field]["table_type"]!=null) { + table_type = data[field]["table_type"] +'-'+data[field]["zone"] + }else{ + table_type = "No Table" + + } + row ='
' +'
' +'
' - +''+data[field]["table_type"]+'-'+ data[field]["zone"] +'' + +''+table_type +'' +'' +''+data[field]["order_id"]+'' +'
' @@ -145,9 +153,22 @@ $(document).on('turbolinks:load', function() { url: '/oqs/' + orderNo, data: { 'status' : order_status }, success: function(res){ - for (i = 0; i < res.length; i++) { - var data = JSON.stringify(res[i]); + // console.log(res); + for (i = 0; i < res["items"].length; i++) { + var data = JSON.stringify(res["items"][i]); var parse_data = JSON.parse(data); + var assigned_order_items = []; + var assigned_order_item_id = ''; + if(res["assigned_order_items"]!= undefined && res["assigned_order_items"]!=''){ + assigned_order_items = JSON.parse(JSON.stringify(res["assigned_order_items"])); + $.each(assigned_order_items,function(key,value){ + if(value[parse_data.order_items_id] != undefined){ + assigned_order_item_id = value[parse_data.order_items_id]; + } + }); + } + // console.log(assigned_order_item_id); + var set_menu_items = parse_data.set_menu_items; var set_instance_items = ""; if(set_menu_items!=null){ @@ -159,10 +180,18 @@ $(document).on('turbolinks:load', function() { } if (oqs_id > 0){ - var order_item_row = "" + - "" + parse_data.item_name + set_instance_items + "" + - "" + parse_data.qty + "" + - ""; + if(assigned_order_item_id != ''){ + var order_item_row = "" + + "" + parse_data.item_name + set_instance_items + "" + + "" + parse_data.qty + "" + + ""; + }else{ + var order_item_row = "" + + "" + parse_data.item_name + set_instance_items + "" + + "" + parse_data.qty + "" + + ""; + } + }else{ var order_item_row = "" + "" + parse_data.item_name + set_instance_items + "" + @@ -185,7 +214,7 @@ $(document).on('turbolinks:load', function() { $(document).on('click', '.order-item-edit', function(event){ var _self = $(this); // To know in ajax return var assigned_item_id=$(this).attr('id').substr(5); - window.location.href = '/oqs/'+ assigned_item_id + "/edit" + window.location.href = '/oqs/'+ assigned_item_id + "/edit/oqs"; }); // complete for queue item diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 25b9aa9b..69ac19d4 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -1,7 +1,7 @@ $(function() { - - type = $('#type').val(); - modify_order = $('#modify_order').val(); + var role = $('#role').val(); + type = window.location.href.indexOf("quick_service"); + modify_order = window.location.href.indexOf("modify_order"); //click menu sidebar menu category $(".product").on("click", function(){ var url = $(this).attr('data-ref'); @@ -76,8 +76,8 @@ $(function() { } //end show list function //click menu sidebar menu category - // $(".menu_category").on("click", function(){ $(document).on('click', '.menu_category', function(event){ + event.preventDefault(); var menu_id = $(this).attr("data-id"); var url = "get_menu_category/"+menu_id; show_menu_item_list(url); @@ -88,13 +88,16 @@ $(function() { function show_menu_item_list(url_item){ var menu_list = $('.menu_items_list'); menu_list.empty(); - - if (modify_order=="true" && type =="true") { - url_item = '../../../addorders/'+url_item; - }if(modify_order=="false" && type =="true"){ - url_item = 'addorders/'+url_item - }else{ - url_item = url_item; + + type = window.location.href.indexOf("quick_service"); + modify_order = window.location.href.indexOf("modify_order"); + if (type != -1 && modify_order != -1) { + url_item = '../../../addorders/'+url_item; + }if(modify_order == -1 && type != -1){ + url_item = 'addorders/'+url_item; + } + if (type ==-1 && modify_order == -1){ + url_item = url_item } //Start Ajax @@ -756,10 +759,10 @@ $(function() { e.preventDefault(); $("#oqs_loading_wrapper").show(); - type = $('#type').val(); - if (type == 'true') { - type = 'cashier' + type = window.location.href.indexOf("quick_service"); + if (type != -1) { + type = 'quick_service' var table_type = $('#table_type').text(); var table_id = $('#table_id').val(); var customer_id = $('#customer_id').val(); @@ -773,42 +776,45 @@ $(function() { var booking_id = $('#booking_id').text(); var ajax_url = '../addorders/create'; } - if (!booking_id.length > 0) { + var order_items = JSON.stringify(get_order_item_rows()); + if (booking_id.length > 0) { var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "",'booking_id':booking_id, 'table_id': table_id, - 'order_items': order_items }; - } - - var order_items = JSON.stringify(get_order_item_rows()); - - var params = {'order_source': type, 'order_type': "dine_in", + 'order_items': order_items,'create_type' : "create_only" }; + }else{ + var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "", 'table_id': table_id, - 'order_items': order_items }; - if (table_id.length>0) { - $.ajax({ - type: "POST", - url: ajax_url, - data: params, - dataType: "json", - success:function(result){ - - if(table_type == "Table"){ - window.location.href = "/origami/table/" + table_id - } - else { - window.location.href = "/origami/room/" + table_id - } - } - }); - }else{ - $(this).removeAttr('disabled', ''); - $("#oqs_loading_wrapper").hide(); - - swal("Opps","Please Select Table or Room","warning"); + 'order_items': order_items,'create_type' : "create_only" }; } + + // if (table_id.length>0 || role == 'waiter') { + $.ajax({ + type: "POST", + url: ajax_url, + data: params, + dataType: "json", + success:function(result){ + if (type == "quick_service") { + window.location.href = "/origami/quick_service" + }else{ + if(table_type == "Table"){ + window.location.href = "/origami/table/" + table_id + } + else { + window.location.href = "/origami/room/" + table_id + } + } + } + }); + // }else{ + // $(this).removeAttr('disabled', ''); + // $("#oqs_loading_wrapper").hide(); + + // swal("Opps","Please Select Table or Room","warning"); + // } }); @@ -817,9 +823,10 @@ $(function() { $(this).attr('disabled', 'disabled'); e.preventDefault(); type = "quick_service" + modify_order = window.location.href.indexOf("modify_order"); $("#oqs_loading_wrapper").show(); console.log(modify_order) - if (modify_order == "true") { + if (modify_order !=-1) { console.log($('#sale_id').text()) var ajax_url = '../../../quick_service/update_modify_order'; var table_type = $('#table_type').text(); @@ -835,21 +842,20 @@ $(function() { var booking_id = $('#booking_id').text(); var sale_id = "" } - - if (!booking_id.length > 0) { + var order_items = JSON.stringify(get_order_item_rows()); + if (booking_id.length > 0) { var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "",'booking_id':booking_id, 'table_id': table_id, - 'order_items': order_items }; - } - var order_items = JSON.stringify(get_order_item_rows()); - - var params = {'order_source': type, 'order_type': "dine_in", + 'order_items': order_items,'sale_id': sale_id,'create_type': "create_pay" }; + }else{ + var params = {'order_source': type, 'order_type': "dine_in", 'customer_id': customer_id, 'guest_info': "", 'table_id': table_id, - 'order_items': order_items,'sale_id': sale_id }; - console.log(params) + 'order_items': order_items,'sale_id': sale_id,'create_type': "create_pay" }; + } + $.ajax({ type: "POST", url: ajax_url, @@ -858,7 +864,11 @@ $(function() { success:function(result){ console.log(result) if (result.status) { + if (result.data == null){ + window.location.href = '/origami/quick_service/pending_order/' + $('#sale_id').text(); + }else{ window.location.href = "/origami/sale/"+result.data["sale_id"]+"/"+type+"/payment" + } } } }); @@ -975,7 +985,7 @@ $(function() { $("#back").on("click", function(){ var table_id = $('#table_id').text(); var table_type = $('#table_type').text(); - type = $('#type').val(); + type = window.location.href.indexOf("quick_service"); if (type == 'true') { var table_type = $('#table_id').find("option:selected").data('type'); var table_id = $('#table_id').val(); @@ -1089,7 +1099,8 @@ $(function() { //click menu sidebar menu category - $(".sub_click").on("click", function(){ + $(document).on('click', '.sub_click', function(event){ + event.preventDefault(); var menu_id = $(this).attr("data-id"); var url = "get_menu_sub_category/"+menu_id; sub_category = $(this).find('.sub_category_list'); @@ -1100,11 +1111,12 @@ $(function() { //show menu item list when click menu category function show_sub_category_list(url,sub_category){ - if (modify_order == "true" && type =="true") { + if (type != -1 && modify_order != -1) { var url = "../../../addorders/"+url; - }if(modify_order=="false" && type =="true"){ + }if(modify_order== -1 && type != -1){ var url = 'addorders/'+url; - }else{ + } + if (type ==-1 && modify_order == -1){ var url = url; } diff --git a/app/assets/javascripts/reports/product_sale.coffee b/app/assets/javascripts/reports/product_sale.coffee new file mode 100644 index 00000000..24f83d18 --- /dev/null +++ b/app/assets/javascripts/reports/product_sale.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/addorder.scss b/app/assets/stylesheets/addorder.scss index faff5850..d8adba16 100755 --- a/app/assets/stylesheets/addorder.scss +++ b/app/assets/stylesheets/addorder.scss @@ -175,7 +175,7 @@ section.content{ text-align: center; } -.add_icon{ +.menu_item_box{ cursor: pointer; } diff --git a/app/assets/stylesheets/reports/product_sale.scss b/app/assets/stylesheets/reports/product_sale.scss new file mode 100644 index 00000000..cb0b9a13 --- /dev/null +++ b/app/assets/stylesheets/reports/product_sale.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the reports/ProductSale controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 552bc118..330c5c1f 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,128 +1,26 @@ class ApplicationController < ActionController::Base include LoginVerification + #before_action :check_installation protect_from_forgery with: :exception + helper_method :shop_detail # lookup domain for db from provision - before_action :lookup_domain, :set_locale - - helper_method :current_company,:current_login_employee,:current_user,:shop_detail + # before_action :set_locale + # helper_method :current_company,:current_login_employee,:current_user # alias_method :current_user, :current_login_employee,:current_user #this is base api base controller to need to inherit. #all token authentication must be done here #response format must be set to JSON - #change locallization - def set_locale - I18n.locale = params[:locale] || I18n.default_locale - end - - # RESTful url for localize - def default_url_options - { locale: I18n.locale } - end - - def lookup_domain - if request.subdomain.present? && request.subdomain != "www" - from = request.subdomain.downcase + "." + request.domain.downcase - @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase - if (!@license.nil?) - # logger.info "Location - " + @license.name - ActiveRecord::Base.establish_connection(website_connection(@license)) - # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema - else - # reconnect_default_db - logger.info 'License is nil' - # redirect_to root_url(:host => request.domain) + "store_error" - render :json => [{ status: false, message: 'Invalid Access!'}] - end - else - # check for license file - # if check_license - # current_license(ENV["SX_PROVISION_URL"]) - # else - # redirect_to activate_path - # end - end - end - - def current_license(url) - @license = License.new(url) - flag = @license.detail_with_local_file() - if (flag == 0) - flash[:notice] = 'Expired or No License!' - elsif (flag == 2) - flash[:notice] = 'Expiring! Please, License extend...' - else - puts "RUN SAY BYAR" - end - end - - def cache_license(url, lookup) - @license = License.new(url, lookup) - - if (@license.detail_with_local_cache(lookup) == true) - return @license - else - return nil - end - end - - def website_connection(license) - default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, - :username => license.dbusername, :password => license.dbpassword) - - end - - def reconnect_default_db - ActiveRecord::Base.establish_connection(Rails.env) - end - - # Regular database.yml configuration hash - def default_connection - @default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup - end - rescue_from CanCan::AccessDenied do |exception| flash[:warning] = exception.message redirect_to root_path end - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] - end - - # Get current Cashier - def get_cashier - @cashier = Employee.where("role = 'cashier' AND token_session <> ''") - end - - def current_company - begin - return Company.first - rescue - return nil - end - - end - def shop_detail @shop = Shop.first end - - def current_login_employee - if (!session[:session_token].nil?) - @employee = Employee.find_by_token_session(session[:session_token]) - end - end - - private - def check_license - if License.check_license_file - return true - end - return false - end end diff --git a/app/controllers/base_crm_controller.rb b/app/controllers/base_crm_controller.rb index 675b3060..3b9e0176 100755 --- a/app/controllers/base_crm_controller.rb +++ b/app/controllers/base_crm_controller.rb @@ -1,5 +1,5 @@ class BaseCrmController < ActionController::Base - include LoginVerification + include LoginVerification layout "CRM" #before_action :check_installation @@ -30,5 +30,4 @@ class BaseCrmController < ActionController::Base def shop_detail @shop = Shop.first end - end diff --git a/app/controllers/base_inventory_controller.rb b/app/controllers/base_inventory_controller.rb index b3a9141d..a88a3abb 100755 --- a/app/controllers/base_inventory_controller.rb +++ b/app/controllers/base_inventory_controller.rb @@ -1,5 +1,5 @@ class BaseInventoryController < ActionController::Base - include LoginVerification + include LoginVerification layout "inventory" #before_action :check_installation @@ -20,5 +20,4 @@ class BaseInventoryController < ActionController::Base def shop_detail @shop = Shop.first end - end diff --git a/app/controllers/base_oqs_controller.rb b/app/controllers/base_oqs_controller.rb index 436be205..0f093913 100755 --- a/app/controllers/base_oqs_controller.rb +++ b/app/controllers/base_oqs_controller.rb @@ -30,5 +30,4 @@ class BaseOqsController < ActionController::Base def shop_detail @shop = Shop.first end - end diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index fdd0a57b..8c4f3aaa 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -8,7 +8,6 @@ class BaseOrigamiController < ActionController::Base protect_from_forgery with: :exception helper_method :shop_detail - rescue_from CanCan::AccessDenied do |exception| flash[:warning] = exception.message # redirect_to origami_root_path diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index 16c68397..e96e97c8 100755 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -1,9 +1,9 @@ class BaseReportController < ActionController::Base - include LoginVerification - layout "application" + include LoginVerification + layout "application" - #before_action :check_installation - protect_from_forgery with: :exception + #before_action :check_installation + protect_from_forgery with: :exception helper_method :shop_detail @@ -12,10 +12,6 @@ class BaseReportController < ActionController::Base redirect_to root_path end - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] - end - PERIOD = { "today" => 0, "yesterday" => 1, @@ -85,13 +81,10 @@ class BaseReportController < ActionController::Base end return from, to - - end #Shop Name in Navbor def shop_detail @shop = Shop.first end - end diff --git a/app/controllers/base_waiter_controller.rb b/app/controllers/base_waiter_controller.rb index 1a8a7648..71303213 100755 --- a/app/controllers/base_waiter_controller.rb +++ b/app/controllers/base_waiter_controller.rb @@ -1,5 +1,5 @@ class BaseWaiterController < ActionController::Base - include LoginVerification + include LoginVerification layout "waiter" #before_action :check_installation @@ -7,9 +7,8 @@ class BaseWaiterController < ActionController::Base helper_method :shop_detail - #Shop Name in Navbor - def shop_detail - @shop = Shop.first - end - + #Shop Name in Navbor + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/concerns/license_verification.rb b/app/controllers/concerns/license_verification.rb new file mode 100644 index 00000000..94e9ad91 --- /dev/null +++ b/app/controllers/concerns/license_verification.rb @@ -0,0 +1,88 @@ +module LicenseVerification + extend ActiveSupport::Concern + + included do + before_action :lookup_domain + end + + protected + def lookup_domain + if request.subdomain.present? && request.subdomain != "www" + from = request.subdomain.downcase + "." + request.domain.downcase + @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase + if (!@license.nil?) + # logger.info "Location - " + @license.name + ActiveRecord::Base.establish_connection(website_connection(@license)) + # authenticate_session_token + # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema + else + # reconnect_default_db + logger.info 'License is nil' + # redirect_to root_url(:host => request.domain) + "store_error" + render :json => [{ status: false, message: 'Invalid Access!'}] + end + else + # check for license file + # if check_license + # current_license(ENV["SX_PROVISION_URL"]) + # else + # redirect_to activate_path + # end + end + authenticate_session_token + end + + def authenticate_session_token + token = session[:session_token] + if (token) + #@current_user = User.find_by(api_key: token) + #Rails.logger.debug "token - " + token.to_s + + @user = Employee.authenticate_by_token(token) + if @user + return true + #Maybe log - login? + else + flash[:notice] = 'Invalid Access!' + # return false + end + end + end + + def current_license(url) + @license = License.new(url) + flag = @license.detail_with_local_file() + if (flag == 0) + flash[:notice] = 'Expired or No License!' + elsif (flag == 2) + flash[:notice] = 'Expiring! Please, License extend...' + else + puts "RUN SAY BYAR" + end + end + + def cache_license(url, lookup) + @license = License.new(url, lookup) + + if (@license.detail_with_local_cache(lookup) == true) + return @license + else + return nil + end + end + + def website_connection(license) + default_connection.dup.update(:host => license.dbhost, :database => license.dbschema.to_s.downcase, + :username => license.dbusername, :password => license.dbpassword) + + end + + def reconnect_default_db + ActiveRecord::Base.establish_connection(Rails.env) + end + + # Regular database.yml configuration hash + def default_connection + @default_config ||= ActiveRecord::Base.connection.instance_variable_get("@config").dup + end +end \ No newline at end of file diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb index ab5823de..bb9df067 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -2,15 +2,37 @@ module LoginVerification extend ActiveSupport::Concern included do - before_action :authenticate - helper_method :current_company,:current_login_employee - + before_action :authenticate_session_token + helper_method :current_company, :current_login_employee, :current_user, :get_cashier end + #this is base api base controller to need to inherit. + #all token authentication must be done here + #response format must be set to JSON + def current_company + begin + return Company.first + rescue + return nil + end + end + + def current_login_employee + @employee = Employee.find_by_token_session(session[:session_token]) + end + + def current_user + @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + end + + # Get current Cashiers + def get_cashier + @cashier = Employee.where("role = 'cashier' AND token_session <> ''") + end protected # Authenticate the user with token based authentication - def authenticate + def authenticate authenticate_session_token || render_unauthorized end @@ -18,7 +40,7 @@ module LoginVerification token = session[:session_token] if (token) #@current_user = User.find_by(api_key: token) - Rails.logger.debug "token - " + token.to_s + #Rails.logger.debug "token - " + token.to_s @user = Employee.authenticate_by_token(token) if @user @@ -32,24 +54,11 @@ module LoginVerification redirect_to root_path end - - #this is base api base controller to need to inherit. - #all token authentication must be done here - #response format must be set to JSON - def current_company - begin - return Company.first - rescue - return nil - end - - end - - def current_login_employee - @employee = Employee.find_by_token_session(session[:session_token]) - end - private + def check_license + License.check_license_file + end + def check_installation if current_company.nil? redirect_to install_path diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 357bb0b7..cf18ae9b 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -1,13 +1,17 @@ -class HomeController < ApplicationController +class HomeController < ApplicationController # layout "application", except: [:index, :show] +<<<<<<< HEAD skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy] helper_method :shop_detail +======= + # skip_before_action only: [:index, :show, :create, :update, :destroy] +>>>>>>> 311bef44119baa113cfadf226d6d34e04cfbe991 def index # @employees = Employee.all_emp_except_waiter.order("name asc") @employees = Employee.all.order("name asc") - @login_form = LoginForm.new() + @login_form = LoginForm.new() render "layouts/login_dashboard", layout: false end @@ -48,9 +52,12 @@ class HomeController < ApplicationController elsif @employee.role == "manager" session[:session_token] = @employee.token_session redirect_to dashboard_path - elsif @employee.role == "supervisor" || @employee.role == "waiter" + elsif @employee.role == "supervisor" session[:session_token] = @employee.token_session redirect_to origami_root_path + elsif @employee.role == "waiter" + session[:session_token] = @employee.token_session + redirect_to origami_dashboard_path elsif @employee.role == "account" session[:session_token] = @employee.token_session redirect_to reports_dailysale_index_path @@ -58,63 +65,65 @@ class HomeController < ApplicationController render :index end else - redirect_to origami_root_path, :notice => "Username and Password doesn't match!" + redirect_to root_path, :notice => "Username and Password doesn't match!" end end def dashboard + @from, @to = get_date_range_from_params + @shop = Shop.first today = DateTime.now.strftime('%Y-%m-%d') @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() - @top_products = Sale.top_products(today).sum('i.qty') - @bottom_products = Sale.bottom_products(today).sum('i.qty') - @hourly_sales = Sale.hourly_sales(today).sum(:grand_total) + @top_products = Sale.top_products(today,@from,@to).sum('i.qty') + @bottom_products = Sale.bottom_products(today,@from,@to).sum('i.qty') + @hourly_sales = Sale.hourly_sales(today,@from,@to).sum(:grand_total) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) - @employee_sales = Sale.employee_sales(today) + @employee_sales = Sale.employee_sales(today,@from,@to) .sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)') - @inventories = StockJournal.inventory_balances(today).sum(:balance) + @inventories = StockJournal.inventory_balances(today,@from,@to).sum(:balance) - @total_sale = Sale.total_sale(today) - @total_count = Sale.total_count(today) - @total_card = Sale.total_card_sale(today) - @total_credit = Sale.credit_payment(today) + @total_sale = Sale.total_sale(today,current_user,@from,@to) + @total_count = Sale.total_count(today,current_user,@from,@to) + @total_card = Sale.total_card_sale(today,current_user,@from,@to) + @total_credit = Sale.credit_payment(today,current_user,@from,@to) @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(today) + @total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to) @total_payment_methods.each do |payment| if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" - pay = Sale.payment_sale('card', today) + pay = Sale.payment_sale('card', today, current_user,@from,@to) @sale_data.push({'card' => pay.payment_amount}) else - pay = Sale.payment_sale(payment.payment_method, today) + pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to) @sale_data.push({payment.payment_method => pay.payment_amount}) end end - @summ_sale = Sale.summary_sale_receipt(today) - @total_customer = Sale.total_customer(today) - @total_dinein = Sale.total_dinein(today) - @total_takeaway = Sale.total_takeaway(today) - @total_other_customer = Sale.total_other_customer(today) - @total_membership = Sale.total_membership(today) + @summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to) + @total_customer = Sale.total_customer(today,current_user,@from,@to) + @total_dinein = Sale.total_dinein(today,current_user,@from,@to) + @total_takeaway = Sale.total_takeaway(today,current_user,@from,@to) + @total_other_customer = Sale.total_other_customer(today,current_user,@from,@to) + @total_membership = Sale.total_membership(today,current_user,@from,@to) - @total_order = Sale.total_order(today) - @total_accounts = Sale.total_account(today) + @total_order = Sale.total_order(today,current_user,@from,@to) + @total_accounts = Sale.total_account(today,current_user,@from,@to) @account_data = Array.new @total_accounts.each do |account| - acc = Sale.account_data(account.account_id, today) + acc = Sale.account_data(account.account_id, today,current_user,@from,@to) if !acc.nil? @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end end - @top_items = Sale.top_items(today) - @total_foc_items = Sale.total_foc_items(today) + @top_items = Sale.top_items(today,current_user,@from,@to) + @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to) # get printer info @print_settings = PrintSetting.get_precision_delimiter() @@ -156,7 +165,7 @@ class HomeController < ApplicationController elsif employee.role == "manager" redirect_to dashboard_path elsif employee.role == "waiter" - redirect_to oqs_root_path + redirect_to origami_dashboard_path elsif employee.role == "crm" redirect_to crm_root_path elsif @employee.role == "supervisor" @@ -166,9 +175,24 @@ class HomeController < ApplicationController end end + def get_date_range_from_params + from = params[:from] + to = params[:to] + + if from.present? && to.present? + f_date = DateTime.parse(from) + t_date = DateTime.parse(to) + f_time = Time.mktime(f_date.year,f_date.month,f_date.day,f_date.hour,f_date.min,f_date.sec) + t_time = Time.mktime(t_date.year,t_date.month,t_date.day,t_date.hour,t_date.min,t_date.sec) + from = f_time.beginning_of_day.utc.getlocal + to = t_time.end_of_day.utc.getlocal + end + + return from, to + end + #Shop Name in Navbor def shop_detail @shop = Shop.first end - end diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index 195c3379..ccc1bf3e 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -1,4 +1,5 @@ class InstallController < BaseController + skip_before_action :lookup_domain skip_before_action :verify_authenticity_token # before_action :check_license diff --git a/app/controllers/inventory/inventory_controller.rb b/app/controllers/inventory/inventory_controller.rb index 1a311552..d512a2dc 100755 --- a/app/controllers/inventory/inventory_controller.rb +++ b/app/controllers/inventory/inventory_controller.rb @@ -3,4 +3,10 @@ class Inventory::InventoryController < BaseInventoryController def index @products = InventoryDefinition.all.active.order('created_at desc') end + + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/inventory/inventory_definitions_controller.rb b/app/controllers/inventory/inventory_definitions_controller.rb index 33b7dd75..accb90b4 100755 --- a/app/controllers/inventory/inventory_definitions_controller.rb +++ b/app/controllers/inventory/inventory_definitions_controller.rb @@ -61,6 +61,12 @@ class Inventory::InventoryDefinitionsController < BaseInventoryController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end + private # Use callbacks to share common setup or constraints between actions. def set_inventory_definition diff --git a/app/controllers/inventory/stock_check_items_controller.rb b/app/controllers/inventory/stock_check_items_controller.rb index 18980f29..7a37f789 100755 --- a/app/controllers/inventory/stock_check_items_controller.rb +++ b/app/controllers/inventory/stock_check_items_controller.rb @@ -61,6 +61,12 @@ class Inventory::StockCheckItemsController < BaseInventoryController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end + private # Use callbacks to share common setup or constraints between actions. def set_stock_check_item diff --git a/app/controllers/inventory/stock_checks_controller.rb b/app/controllers/inventory/stock_checks_controller.rb index 52d183de..8e938a3a 100755 --- a/app/controllers/inventory/stock_checks_controller.rb +++ b/app/controllers/inventory/stock_checks_controller.rb @@ -38,6 +38,12 @@ class Inventory::StockChecksController < BaseInventoryController printer.print_stock_check_result(print_settings, stockcheck, stockcheck_items, checker.name, shop_details) end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end + # before_action :set_stock_check, only: [:show, :edit, :update, :destroy] # GET /stock_checks diff --git a/app/controllers/inventory/stock_journals_controller.rb b/app/controllers/inventory/stock_journals_controller.rb index a40fa8ab..11db2efd 100755 --- a/app/controllers/inventory/stock_journals_controller.rb +++ b/app/controllers/inventory/stock_journals_controller.rb @@ -61,6 +61,12 @@ class StockJournalsController < ApplicationController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end + private # Use callbacks to share common setup or constraints between actions. def set_stock_journal diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb index cda55f31..e8d9615d 100755 --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -1,8 +1,17 @@ class Oqs::EditController < BaseOqsController def index assigned_item_id = params[:id] - assigned_item = AssignedOrderItem.find(assigned_item_id) - @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_instance_code='#{ assigned_item.instance_code }'"); + @link_type = params[:type] + @dining_type = nil + if params[:type] == 'oqs' + assigned_item = AssignedOrderItem.find(assigned_item_id) + @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_instance_code='#{ assigned_item.instance_code }'") + else + assigned_item = OrderItem.find(assigned_item_id) + dining = DiningFacility.find_by_id(params[:type]) + @dining_type = dining.type + @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_instance_code='#{ assigned_item.item_instance_code }'") + end end def update diff --git a/app/controllers/oqs/home_controller.rb b/app/controllers/oqs/home_controller.rb index e71075ec..58b2910b 100755 --- a/app/controllers/oqs/home_controller.rb +++ b/app/controllers/oqs/home_controller.rb @@ -14,19 +14,19 @@ class Oqs::HomeController < BaseOqsController @queue_stations = OrderQueueStation.all @queue_completed_item = completed_order(@filter) - # if !@queue_completed_item.empty? - # @queue_completed_item.each do |queue_item| - # if !queue_item.set_menu_items.nil? - # instance_item_sets = JSON.parse(JSON.parse(queue_item.set_menu_items)) - # arr_instance_item_sets = Array.new - # instance_item_sets.each do |instance_item| - # item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name - # arr_instance_item_sets.push(item_instance_name) - # end - # queue_item.set_menu_items = arr_instance_item_sets - # end - # end - # end + if !@queue_completed_item.empty? + @queue_completed_item.each do |queue_item| + if !queue_item.set_menu_items.nil? + instance_item_sets = JSON.parse(JSON.parse(queue_item.set_menu_items)) + arr_instance_item_sets = Array.new + instance_item_sets.each do |instance_item| + item_instance_name = MenuItemInstance.find_by_item_instance_code(instance_item["item_instance_code"]).item_instance_name + arr_instance_item_sets.push(item_instance_name) + end + queue_item.set_menu_items = arr_instance_item_sets + end + end + end if !@filter.nil? @count = queue_items_count_query(false,@filter) @@ -60,6 +60,7 @@ class Oqs::HomeController < BaseOqsController # Get Order items def get_order_items items = [] + assigned_items = [] order_no = params[:order_no] status = params[:status] # dining = DiningFacility.find_by_name(table_name); @@ -90,6 +91,11 @@ class Oqs::HomeController < BaseOqsController if !items.empty? items.each do |item| + assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id) + if !assigned_order_items.nil? + assigned_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id}) + end + if !item.set_menu_items.nil? instance_item_sets = JSON.parse(item.set_menu_items) arr_instance_item_sets = Array.new @@ -101,7 +107,7 @@ class Oqs::HomeController < BaseOqsController end end end - render :json => items.to_json + render :json => {'items' => items, 'assigned_order_items' => assigned_items } end def get_items_by_oqs diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 13c1e246..c3e6766e 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -37,9 +37,10 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController def get_menu_category () if (params[:id]) - puts params[:id] + #Pull this menu @menu = MenuCategory.find_by_id(params[:id]) + # puts @menu.menu_items[1].item_attributes.to_json return @menu else @@ -49,7 +50,6 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController def get_menu() if (params[:id]) - puts params[:id] #Pull this menu @menu = Menu.find_by_id(params[:id]) @menu_category = MenuCategory.where("menu_id='#{@menu.id}'").order("order_by asc") @@ -61,10 +61,13 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController end def get_menu_sub_category () + id = params[:id] + if (id) #Pull this menu @sub_menu = MenuCategory.where("menu_category_id = #{id}").active + # puts @menu.menu_items[1].item_attributes.to_json return @sub_menu end @@ -153,13 +156,18 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController end @status, @booking = @order.generate - - if @status && @booking && @order.source == 'quick_service' + if current_user.role != "waiter" && params[:create_type] == "create_pay" + if @status && @booking && @order.source == 'quick_service' - @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) - result = {:status=> @status, :data => @sale } + @status, @sale = Sale.request_bill(@order,current_user,current_login_employee) + result = {:status=> @status, :data => @sale } + render :json => result.to_json + end + else + result = {:status=> @status, :data => 0 } render :json => result.to_json end + end # render json for http status code diff --git a/app/controllers/origami/dashboard_controller.rb b/app/controllers/origami/dashboard_controller.rb index a7f6ff15..f888ac57 100644 --- a/app/controllers/origami/dashboard_controller.rb +++ b/app/controllers/origami/dashboard_controller.rb @@ -55,6 +55,7 @@ class Origami::DashboardController < BaseOrigamiController # get printer info @print_settings = PrintSetting.get_precision_delimiter() + @current_user = current_user end end diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 87931f8c..59da5387 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -52,7 +52,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_item.product_name = di["name"] sale_item.item_instance_code = origin_sale_item.item_instance_code sale_item.product_alt_name = "" - sale_item.remark = "Discount" + sale_item.status = "Discount" sale_item.qty = -1 sale_item.unit_price = di["price"].to_f * (-1) @@ -175,7 +175,7 @@ class Origami::DiscountsController < BaseOrigamiController discount_items = [] #destroy all discount sale item sale.sale_items.each do |si| - if si.remark == "Discount" && si.price < 0 + if si.status == "Discount" && si.price < 0 sale.total_amount = (sale.total_amount + si.price.abs) discount_items.push(si) end @@ -343,7 +343,7 @@ class Origami::DiscountsController < BaseOrigamiController # sale_item.sale_id = sale_id # sale_item.product_code = origin_sale_item != nil ? origin_sale_item.product_code : sale_id # sale_item.product_name = product_name - # sale_item.remark = remark + # sale_item.status = remark # sale_item.qty = 1 # sale_item.unit_price = (0-discount_amount.to_f) diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 43fb104f..14a2a93b 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -62,6 +62,7 @@ class Origami::HomeController < BaseOrigamiController @dining.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new + # @assigned_order_items = Array.new if booking.booking_orders.empty? @booking = booking else @@ -84,15 +85,22 @@ class Origami::HomeController < BaseOrigamiController item.set_menu_items = arr_instance_item_sets end @order_items.push(item) + # assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id) + # if !assigned_order_items.nil? + # @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id}) + # end end - accounts = @customer.tax_profiles - puts accounts.to_json - puts "sssssssssss" - puts @customer.tax_profiles - @account_arr =[] - accounts.each do |acc| - account = TaxProfile.find(acc) - @account_arr.push(account) + @account_arr = Array.new + if @customer.tax_profiles + accounts = @customer.tax_profiles + puts accounts.to_json + puts "sssssssssss" + puts @customer.tax_profiles + @account_arr =[] + accounts.each do |acc| + account = TaxProfile.find(acc) + @account_arr.push(account) + end end end end diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index e7f9f9b2..8bba3800 100755 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -44,7 +44,7 @@ class Origami::OtherChargesController < BaseOrigamiController sale_item.product_code = "Other Charges" sale_item.product_name = "*" + di["name"] sale_item.product_alt_name = "" - sale_item.remark = "Other Charges" + sale_item.status = "Other Charges" sale_item.qty = 1 sale_item.unit_price = di["price"] diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index beb95671..64b0bde5 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -8,7 +8,6 @@ class Origami::PaymentsController < BaseOrigamiController sale_data = Sale.find_by_sale_id(sale_id) sale_items = SaleItem.where("sale_id=?",sale_id) member_info = nil - survey = Survey.find_by_receipt_no(sale_data.receipt_no) # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") @@ -67,7 +66,7 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil,survey) + printer.print_receipt_bill(print_settings,cashier_terminal,sale_items,sale_data,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info, shop_details, "Frt",current_balance,nil) end end @@ -79,7 +78,6 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop::ShopDetail - survey = Survey.find_by_receipt_no(saleObj.receipt_no) # rounding adjustment if shop_details.is_rounding_adj a = saleObj.grand_total % 25 # Modulus @@ -95,7 +93,7 @@ class Origami::PaymentsController < BaseOrigamiController #end rounding adjustment sale_payment = SalePayment.new - sale_payment.process_payment(saleObj, @user, cash, "cash") + sale_payment.process_payment(saleObj, current_user.name, cash, "cash") render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error "}) rebate_amount = nil @@ -153,7 +151,7 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data,survey) + printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Paid",current_balance,card_data) if params[:type] == "quick_service" booking = Booking.find_by_sale_id(sale_id) @@ -164,7 +162,7 @@ class Origami::PaymentsController < BaseOrigamiController end booking.booking_orders.each do |order| - Order.pay_process_order_queue(order.order_id,table_id,sale_id) + Order.pay_process_order_queue(order.order_id,table_id) end end end @@ -192,9 +190,17 @@ class Origami::PaymentsController < BaseOrigamiController @table_no = '' @dining = '' - @shop = Shop::ShopDetail + @shop = Shop::ShopDetail #show shop info saleObj = Sale.find(sale_id) + + #total customer with individual total amount + @individual_total = Array.new + if !saleObj.equal_persons.nil? + per_person_amount = saleObj.grand_total.to_f / saleObj.equal_persons.to_i + @individual_total.push({'total_customer' => saleObj.equal_persons.to_i, 'per_person_amount' => per_person_amount.to_f }) + end + # rounding adjustment if @shop.is_rounding_adj a = saleObj.grand_total % 25 # Modulus @@ -211,7 +217,9 @@ class Origami::PaymentsController < BaseOrigamiController @rounding_adj = @sale_data.rounding_adjustment end #end rounding adjustment - + + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() #get customer amount @customer = Customer.find(@sale_data.customer_id) @@ -281,7 +289,6 @@ class Origami::PaymentsController < BaseOrigamiController member_info = nil saleObj = Sale.find(sale_id) - survey = Survey.find_by_receipt_no(saleObj.receipt_no) # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") @@ -335,7 +342,7 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Re-print",current_balance,card_data,survey) + printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "Re-print",current_balance,card_data) end end @@ -343,21 +350,22 @@ class Origami::PaymentsController < BaseOrigamiController cash = params[:cash] sale_id = params[:sale_id] sub_total = params[:sub_total] + remark = params[:remark] member_info = nil rebate_amount = nil current_balance = nil if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) - survey = Survey.find_by_receipt_no(saleObj.receipt_no) - if saleObj.discount_type == "member_discount" saleObj.update_attributes(rounding_adjustment: 0) saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0) end + saleObj.update_attributes(rounding_adjustment: 0) + sale_payment = SalePayment.new - sale_payment.process_payment(saleObj, @user, cash, "foc") + sale_payment.process_payment(saleObj, current_user.name, cash, "foc" ,remark) # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") @@ -394,7 +402,20 @@ class Origami::PaymentsController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(saleObj.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC",nil,nil,survey) + printer.print_receipt_bill(print_settings,cashier_terminal,saleObj.sale_items,saleObj,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "FOC",nil,nil) + + if params[:type] == "quick_service" + booking = Booking.find_by_sale_id(sale_id) + if booking.dining_facility_id.to_i>0 + table_id = booking.dining_facility_id + else + table_id = 0 + end + + booking.booking_orders.each do |order| + Order.pay_process_order_queue(order.order_id,table_id) + end + end end end end diff --git a/app/controllers/origami/pending_order_controller.rb b/app/controllers/origami/pending_order_controller.rb index 4333046c..9a413316 100644 --- a/app/controllers/origami/pending_order_controller.rb +++ b/app/controllers/origami/pending_order_controller.rb @@ -2,20 +2,43 @@ class Origami::PendingOrderController < BaseOrigamiController def index # @dining= DiningFacility.where("status = 'occupied'") # @order = Order.where("DATE_FORMAT(date,'%Y-%m-%d') = ? and status = 'billed' and source = 'quick_service'",DateTime.now.strftime('%Y-%m-%d')) - @sale = Sale.pending_order + @sale = Sale.pending_sale + @order = Sale.pending_order + end def show - @sales = Sale.pending_order - @sale = Sale.find(params[:sale_id]) - @order = SaleOrder.find_by_sale_id(@sale.sale_id).order_id - @booking = BookingOrder.find_by_order_id(@order).booking_id - if Booking.find(@booking).dining_facility_id.to_i > 0 - @table_id = Booking.find(@booking).dining_facility_id + @sales = Sale.pending_sale + @orders = Sale.pending_order + @id = params[:sale_id] + if(@id[0,3] == "SAL") + @sale = Sale.find(@id) + @order = SaleOrder.find_by_sale_id(@sale.sale_id).order_id + @booking = BookingOrder.find_by_order_id(@order).booking_id + @bookings = Booking.find(@booking) + @status = "sale" + else + # @booking = BookingOrder.find_by_order_id(@order).booking_id + @bookings = Booking.find(@id) + @status = "order" + + @order_items = Array.new + @bookings.booking_orders.each do |booking_order| + @order = Order.find(booking_order.order_id) + if (@order.status == "new") + @order.order_items.each do |item| + @order_items.push(item) + end + end + end + end + puts @status + if @bookings.dining_facility_id.to_i > 0 + @table_id = Booking.find(@bookings.booking_id).dining_facility_id @dining = DiningFacility.find(@table_id) else @table_id = nil @dining = nil end + end - end diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index ef170480..44dcfcb8 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -14,7 +14,7 @@ class Origami::QuickServiceController < ApplicationController # @rooms = Room.all.active.order('zone_id asc').group("zone_id") # @all_table = Table.all.active.order('status desc') # @all_room = Room.all.active.order('status desc') - render "origami/addorders/detail" + render "origami/addorders/detail" end def modify_order @@ -134,21 +134,26 @@ class Origami::QuickServiceController < ApplicationController end @status, @booking = @order.generate - - if @status && @booking && @order.source == 'quick_service' - if params[:sale_id] - @sale = Sale.find(params[:sale_id]) - if @order.table_id.to_i > 0 - @table_id = @order.table_id - else - @table_id = nil + if(params[:sale_id][0,3] == "SAL") + if @status && @booking && @order.source == 'quick_service' + if params[:sale_id] + @sale = Sale.find(params[:sale_id]) + if @order.table_id.to_i > 0 + @table_id = @order.table_id + else + @table_id = nil + end + update = Sale.add_to_existing_pending_invoice(@table_id,params[:sale_id],@booking) end - update = Sale.add_to_existing_pending_invoice(@table_id,params[:sale_id],@booking) - end - - result = {:status=> true, :data => @sale } - render :json => result.to_json - end + + result = {:status=> true, :data => @sale } + render :json => result.to_json + end + else + result = {:status=> true, :data => nil } + render :json => result.to_json + end + end def get_menu_category () diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index 10c1dc9f..3bc08681 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -8,6 +8,9 @@ class Origami::RequestBillsController < ApplicationController if !ShiftSale.current_shift.nil? order_id = params[:id] # order_id bk_order = BookingOrder.find_by_order_id(order_id) + puts params[:id] + puts bk_order + puts bk_order.booking_id check_booking = Booking.find_by_booking_id(bk_order.booking_id) if check_booking.sale_id.nil? diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index d4f1cd67..f3b11556 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -58,6 +58,7 @@ class Origami::RoomsController < BaseOrigamiController @room.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' @order_items = Array.new + # @assigned_order_items = Array.new booking.booking_orders.each do |booking_order| order = Order.find(booking_order.order_id) @customer = order.customer @@ -78,6 +79,10 @@ class Origami::RoomsController < BaseOrigamiController item.set_menu_items = arr_instance_item_sets end @order_items.push(item) + # assigned_order_items = AssignedOrderItem.find_by_item_code_and_instance_code_and_order_id(item.item_code,item.item_instance_code,item.order_id) + # if !assigned_order_items.nil? + # @assigned_order_items.push({item.order_items_id => assigned_order_items.assigned_order_item_id}) + # end end end end diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 524f4895..72df82ac 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -16,8 +16,10 @@ class Origami::SaleEditController < BaseOrigamiController # create item void. make duplicate old record and update qty and price def item_void saleitemId = params[:sale_item_id] + remark = params[:remark] saleitemObj = SaleItem.find(saleitemId) - saleitemObj.remark = 'void' + saleitemObj.status = 'void' + saleitemObj.remark = remark saleitemObj.save @newsaleitem = SaleItem.new @newsaleitem = saleitemObj.dup @@ -27,11 +29,24 @@ class Origami::SaleEditController < BaseOrigamiController @newsaleitem.is_taxable = 1 @newsaleitem.taxable_price = saleitemObj.taxable_price * -1 @newsaleitem.product_name = saleitemObj.product_name + ' (VOID)' + @newsaleitem.remark = remark @newsaleitem.save # re-calc tax saleObj = Sale.find(saleitemObj.sale_id) + + booking = Booking.find_by_sale_id(saleitemObj.sale_id) + booking.booking_orders.each do |bo| + order = Order.find(bo.order_id) + order.order_items.each do |o| + if saleitemObj.product_code == o.item_code + o.qty = saleitemObj.qty * -1 + o.price = saleitemObj.price * -1 + o.save + end + end + end action_by = current_user.id remark = "Void Sale Item ID #{saleitemObj.sale_item_id} | Receipt No #{saleObj.receipt_no} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}" sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,saleObj.cashier_id, action_by,remark,"SALEITEMVOID" ) @@ -42,8 +57,10 @@ class Origami::SaleEditController < BaseOrigamiController def item_foc saleitemId = params[:sale_item_id] + remark = params[:remark] saleitemObj = SaleItem.find(saleitemId) - saleitemObj.remark = 'foc' + saleitemObj.status = 'foc' + saleitemObj.remark = remark saleitemObj.save @newsaleitem = SaleItem.new @newsaleitem = saleitemObj.dup @@ -53,6 +70,7 @@ class Origami::SaleEditController < BaseOrigamiController @newsaleitem.taxable_price = saleitemObj.taxable_price * -1 @newsaleitem.price = saleitemObj.price * -1 @newsaleitem.product_name = saleitemObj.product_name + ' (FOC)' + @newsaleitem.remark = remark @newsaleitem.save # re-calc tax @@ -71,7 +89,7 @@ class Origami::SaleEditController < BaseOrigamiController # update_qty = params[:update_qty] # update_price = params[:update_price] # saleitemObj = SaleItem.find(saleitemId) - # saleitemObj.remark = 'void' + # saleitemObj.status = 'void' # saleitemObj.save # @newsaleitem = SaleItem.new # @newsaleitem = saleitemObj.dup @@ -111,6 +129,18 @@ class Origami::SaleEditController < BaseOrigamiController # re-calc tax saleObj = Sale.find(saleitemObj.sale_id) + + order_id = SaleOrder.find_by_sale_id(saleitemObj.sale_id).order_id + order = Order.find(order_id) + + order.order_items.each do |o| + if saleitemObj.product_code == o.item_code + o.qty = update_qty + o.price = update_price + o.save + end + end + saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount) ProductCommission.edit_product_commission(saleitemObj) @@ -123,7 +153,7 @@ class Origami::SaleEditController < BaseOrigamiController both = SaleItem.where('product_code=?', saleitemObj.product_code) both.each do |item| if item.qty.to_i > 0 - item.remark = nil + item.status = nil item.save end end @@ -148,7 +178,7 @@ class Origami::SaleEditController < BaseOrigamiController if item.qty.to_i < 0 item.destroy else - item.remark = nil + item.status = nil end item.save ProductCommission.remove_product_commission(item) diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index cb2cc830..19def9b6 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -61,7 +61,21 @@ class Origami::ShiftsController < BaseOrigamiController end if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + + close_cashier_pdf = Lookup.collection_of("print_settings") unique_code = "CloseCashierPdf" + + if !close_cashier_pdf.empty? + close_cashier_pdf.each do |close_cashier| + if close_cashier[0] == 'CloseCashierCustomisePdf' + if close_cashier[1] == '1' + unique_code="CloseCashierCustomisePdf" + else + unique_code="CloseCashierPdf" + end + end + end + end shop_details = Shop.find(1) #get tax shift_obj = ShiftSale.where('id =?',@shift.id) @@ -73,12 +87,16 @@ class Origami::ShiftsController < BaseOrigamiController @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') @total_member_discount = ShiftSale.get_total_member_discount(@shift) + @total_dinein = ShiftSale.get_total_dinein(@shift).total_dinein_amount + @total_takeway = ShiftSale.get_total_takeway(@shift).total_takeway_amount + @total_other_charges = ShiftSale.get_total_other_charges(@shift).total_other_charges_amount + # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) - + #byebug printer = Printer::CashierStationPrinter.new(print_settings) - printer.print_close_cashier(print_settings,cashier_terminal,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount) + printer.print_close_cashier(print_settings,cashier_terminal,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges) end end Employee.logout(session[:session_token]) @@ -102,8 +120,7 @@ class Origami::ShiftsController < BaseOrigamiController # Calculate price_by_accounts @total_amount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'amount') @total_discount_by_account = ShiftSale.calculate_total_price_by_accounts(@shift,'discount') - @total_member_discount = ShiftSale.get_total_member_discount(@shift) - + @total_member_discount = ShiftSale.get_total_member_discount(@shift) end end diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index db9e0418..1790624a 100644 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -8,6 +8,7 @@ class Origami::SplitBillController < BaseOrigamiController @orders = Array.new @order_items = Array.new @sale_data = Array.new + @current_user = current_user table_bookings = Booking.where("dining_facility_id = #{dining_id} and sale_id IS NOT NULL") if !table_bookings.nil? @@ -97,16 +98,16 @@ class Origami::SplitBillController < BaseOrigamiController cashier_zone = CashierTerminalByZone.find_by_zone_id(table.zone_id) else table = nil + cashier_zone = nil end # shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_zone.cashier_terminal_id,nil) # get_cashier_by_terminal = Employee.find(shift_by_terminal.employee_id) - get_cashier_by_terminal = current_user if booking if booking.sale_id.nil? sale = Sale.new - status, sale_id = sale.generate_invoice_from_booking(params[:booking_id], current_user, get_cashier_by_terminal) + status, sale_id = sale.generate_invoice_from_booking(params[:booking_id], current_user, current_user) sale_data = Sale.find_by_sale_id(sale_id) else status = true @@ -127,6 +128,7 @@ class Origami::SplitBillController < BaseOrigamiController if !orders.nil? orders.each do |order| + BookingOrder.find_by_order_id(order["id"]).delete BookingOrder.create({:booking_id => booking.booking_id, :order_id => order["id"]}) end elsif !order_items.nil? @@ -193,6 +195,8 @@ class Origami::SplitBillController < BaseOrigamiController end end + puts new_order_status + if new_order_status BookingOrder.find_by_order_id(odr_id).delete BookingOrder.create({:booking_id => booking.booking_id, :order_id => odr_id}) @@ -208,17 +212,7 @@ class Origami::SplitBillController < BaseOrigamiController end # begin - order = Order.new - order.source = "cashier" - order.order_type = order_type - order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile - order.item_count = order_items.count - order.status = "new" - order.table_id = params[:dining_id] # this is dining facilities's id - order.waiters = current_user.name - order.employee_name = current_user.name - order.guest_info = nil - order.save! + order = create_order(params,order_type,order_items.count,current_user) BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id}) @@ -242,6 +236,8 @@ class Origami::SplitBillController < BaseOrigamiController end end + puts new_order_status + if new_order_status BookingOrder.find_by_order_id(order_id).delete BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_id}) @@ -260,17 +256,7 @@ class Origami::SplitBillController < BaseOrigamiController end # begin - order = Order.new - order.source = "cashier" - order.order_type = order_type - order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile - order.item_count = order_items.count - order.status = "new" - order.table_id = params[:dining_id] # this is dining facilities's id - order.waiters = current_user.name - order.employee_name = current_user.name - order.guest_info = nil - order.save! + order = create_order(params,order_type,order_items.count,current_user) BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id}) @@ -280,7 +266,9 @@ class Origami::SplitBillController < BaseOrigamiController end end else - if order_ids.count == 1 && order_id_count > 0 && order_item_count == 1 + # puts order_ids + if order_ids.count == 1 && order_id_count == 0 && order_item_count == 1 + BookingOrder.find_by_order_id(order_ids[0]).delete BookingOrder.create({:booking_id => booking.booking_id, :order_id => order_ids[0]}) order_items.each do |order_item| update_order_item(order_ids[0], order_item) @@ -297,17 +285,7 @@ class Origami::SplitBillController < BaseOrigamiController end # begin - order = Order.new - order.source = "cashier" - order.order_type = order_type - order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile - order.item_count = order_items.count - order.status = "new" - order.table_id = params[:dining_id] # this is dining facilities's id - order.waiters = current_user.name - order.employee_name = current_user.name - order.guest_info = nil - order.save! + order = create_order(params,order_type,order_items.count,current_user) BookingOrder.create({:booking_id => booking.booking_id, :order_id => order.order_id}) @@ -319,17 +297,12 @@ class Origami::SplitBillController < BaseOrigamiController end sale = Sale.new - status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, get_cashier_by_terminal) - sale_data = Sale.find_by_sale_id(sale_id) + status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, current_user) end - # Bind shift sale id to sale - # sale_data.shift_sale_id = shift_by_terminal.id - # sale_data.save - Promotion.promo_activate(sale) - BillBroadcastJob.perform_later(table) + ActionCable.server.broadcast "bill_channel",table: table render :json => { status: status } else @@ -337,9 +310,35 @@ class Origami::SplitBillController < BaseOrigamiController end end + def create_order(params,order_type,items_count,current_user) + order = Order.new + order.source = "cashier" + order.order_type = order_type + order.customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile + order.item_count = items_count + order.status = "new" + order.table_id = params[:dining_id] # this is dining facilities's id + order.waiters = current_user.name + order.employee_name = current_user.name + order.guest_info = nil + order.save! + + return order + end + def update_order_item(order_id, order_item) orderItem = OrderItem.find(order_item["id"]) if orderItem.qty.to_f != order_item['qty'].to_f + set_menu_items_obj = Array.new + if !orderItem.set_menu_items.nil? + instance_item_sets = JSON.parse(orderItem.set_menu_items) + instance_item_sets.each_with_index do |instance_item, instance_index| + instance_item_sets[instance_index]["quantity"] = (instance_item["quantity"].to_i - order_item['qty'].to_i).to_s + set_menu_items_obj.push({'item_instance_code' => instance_item["item_instance_code"], 'quantity' => order_item['qty'].to_i, 'price' => instance_item["price"]}) + end + orderItem.set_menu_items = instance_item_sets.to_json + end + OrderItem.processs_item(orderItem.item_code, orderItem.item_instance_code, orderItem.item_name, @@ -348,7 +347,7 @@ class Origami::SplitBillController < BaseOrigamiController order_item['qty'], orderItem.price, orderItem.options, - orderItem.set_menu_items, + set_menu_items_obj.to_json, order_id, orderItem.item_order_by, orderItem.taxable) @@ -360,4 +359,11 @@ class Origami::SplitBillController < BaseOrigamiController orderItem.save! end + def update_sale + sale = Sale.find(params[:sale_id]) + sale.equal_persons = params[:total_customer].to_i + sale.save! + + render :json => { status: true } + end end diff --git a/app/controllers/origami/surveys_controller.rb b/app/controllers/origami/surveys_controller.rb index 0e4ecd7b..654f8a1a 100644 --- a/app/controllers/origami/surveys_controller.rb +++ b/app/controllers/origami/surveys_controller.rb @@ -84,53 +84,6 @@ class Origami::SurveysController < BaseOrigamiController end end - def create_survey - if shift_by_terminal = ShiftSale.current_open_shift(get_cashier[0].id) - @type = params[:cashier_type] - @sale_id = params[:sale_id] - sale = Sale.find(@sale_id) - - if @type != "quick_service" - dining_facility = DiningFacility.find(params[:dining_id]) - cashier_zone = CashierTerminalByZone.find_by_zone_id(dining_facility.zone_id) - cashier_terminal_id = cashier_zone.cashier_terminal_id - else - shift = ShiftSale.find(sale.shift_sale_id) - cashier_terminal_id = shift.cashier_terminal_id - end - - shift_by_terminal = ShiftSale.find_by_cashier_terminal_id_and_shift_closed_at(cashier_terminal_id,nil) - - if @type != "quick_service" - survey = Survey.find_by_dining_name(dining_facility.name) - else - survey = nil - end - - - if survey.nil? - survey = Survey.new - if @type != "quick_service" - survey.dining_name = dining_facility.name - end - - survey.receipt_no = params[:receipt_no] - survey.shift_id = shift_by_terminal.id - survey.created_by = current_user.name - survey.total_customer = params[:total_customer] - survey.total_amount = params[:total_amount] - survey.save! - else - survey.receipt_no = params[:receipt_no] - survey.total_customer = params[:total_customer] - survey.save! - end - render :json => {status: true} - else - render :json => { status: false, error_message: 'No Current Open Shift!'} - end - end - private # Never trust parameters from the scary internet, only allow the white list through. diff --git a/app/controllers/origami/table_invoices_controller.rb b/app/controllers/origami/table_invoices_controller.rb index 880df1c7..f6190230 100755 --- a/app/controllers/origami/table_invoices_controller.rb +++ b/app/controllers/origami/table_invoices_controller.rb @@ -65,6 +65,8 @@ class Origami::TableInvoicesController < BaseOrigamiController if !lookup_spit_bill[0].nil? @split_bill = lookup_spit_bill[0][1] end + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() end end diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index df9aa439..33ff0d76 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -3,10 +3,9 @@ class Origami::VoidController < BaseOrigamiController def overall_void sale_id = params[:sale_id] - + remark = params[:remark] if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) - survey = Survey.find_by_receipt_no(sale.receipt_no) if sale.discount_type == "member_discount" sale.update_attributes(total_discount: 0) @@ -70,12 +69,8 @@ class Origami::VoidController < BaseOrigamiController end # FOr Sale Audit - action_by = current_user.id - if table.nil? - remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table -> nil" - else - remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" - end + action_by = current_user.name + # remark = "Void Sale ID #{sale_id} | Receipt No #{sale.receipt_no} | Receipt No #{sale.receipt_no} | Table ->#{table.name}" sale_audit = SaleAudit.record_audit_for_edit(sale_id,sale.cashier_id, action_by,remark,"SALEVOID" ) # For Print @@ -125,7 +120,7 @@ class Origami::VoidController < BaseOrigamiController discount_price_by_accounts = SaleItem.get_discount_price_by_accounts(sale.sale_items) printer = Printer::ReceiptPrinter.new(print_settings) - printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil,survey) + printer.print_receipt_bill(print_settings,cashier_terminal,sale.sale_items,sale,customer.name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details, "VOID",current_balance,nil) end #end print diff --git a/app/controllers/reports/product_sale_controller.rb b/app/controllers/reports/product_sale_controller.rb new file mode 100644 index 00000000..38a77115 --- /dev/null +++ b/app/controllers/reports/product_sale_controller.rb @@ -0,0 +1,21 @@ +class Reports::ProductSaleController < BaseReportController + authorize_resource :class => false + + def index + @order_by = 'desc' + if !params[:order_by].nil? + @order_by = params[:order_by] + end + + @sale_data = Sale.get_menu_item_query(@order_by) + + # get printer info + @print_settings = PrintSetting.get_precision_delimiter() + + respond_to do |format| + format.html + format.json + format.xls + end + end +end diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index daeb86f4..796b02ad 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -33,7 +33,7 @@ class Reports::SaleitemController < BaseReportController @from = from @to = to - + # get printer info @print_settings = PrintSetting.get_precision_delimiter() diff --git a/app/controllers/reports/stock_check_controller.rb b/app/controllers/reports/stock_check_controller.rb index 9d5ee37d..c2f2cf0d 100755 --- a/app/controllers/reports/stock_check_controller.rb +++ b/app/controllers/reports/stock_check_controller.rb @@ -17,7 +17,7 @@ class Reports::StockCheckController < BaseReportController @from = from_date @to = to_date # get printer info - @print_settings = PrintSetting.get_precision_delimiter() + @print_settings = PrintSetting.get_precision_delimiter() respond_to do |format| format.html format.xls diff --git a/app/helpers/reports/product_sale_helper.rb b/app/helpers/reports/product_sale_helper.rb new file mode 100644 index 00000000..103bd624 --- /dev/null +++ b/app/helpers/reports/product_sale_helper.rb @@ -0,0 +1,2 @@ +module Reports::ProductSaleHelper +end diff --git a/app/jobs/order_queue_processor_job.rb b/app/jobs/order_queue_processor_job.rb index 12fbff3a..18fdc2dd 100755 --- a/app/jobs/order_queue_processor_job.rb +++ b/app/jobs/order_queue_processor_job.rb @@ -1,7 +1,7 @@ class OrderQueueProcessorJob < ApplicationJob queue_as :default - def perform(order_id, table_id,sale_id=nil) + def perform(order_id, table_id) # Do something later #Order ID order = Order.find(order_id) @@ -9,7 +9,7 @@ class OrderQueueProcessorJob < ApplicationJob #Execute orders and send to order stations if order oqs = OrderQueueStation.new - oqs.process_order(order, table_id,sale_id) + oqs.process_order(order, table_id) end assign_order = AssignedOrderItem.assigned_order_item_by_job(order_id) diff --git a/app/models/ability.rb b/app/models/ability.rb index f0091ef7..33372ac9 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -136,6 +136,7 @@ class Ability #ability for split_bill can :index, :split_bill can :create, :split_bill + can :update_sale, :split_bill elsif user.role == "account" @@ -190,6 +191,9 @@ class Ability elsif user.role == "waiter" can :index, :home can :show, :home + #ability for split_bill + can :index, :split_bill + can :create, :split_bill end end end diff --git a/app/models/license.rb b/app/models/license.rb index cdebdbdd..1cbce908 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -33,7 +33,7 @@ class License ##Get redis connection from connection pool redis = Redis.new cache_license = redis.get(cache_key) - + Rails.logger.info "Cache key - " + cache_key.to_s if cache_license.nil? ##change the d/e key diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index 3c1a39ab..acb06c4f 100755 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -52,7 +52,7 @@ class MenuCategory < ApplicationRecord if from > to h = to_t.hour if h < 12 # before noon - if h = 0 + if h == 0 to = 24 to = to * 3600 + to_t.min* 60 + to_t.sec end diff --git a/app/models/menu_item.rb b/app/models/menu_item.rb index 67a3c823..836e0caf 100755 --- a/app/models/menu_item.rb +++ b/app/models/menu_item.rb @@ -78,7 +78,6 @@ class MenuItem < ApplicationRecord end end - # private # def generate_menu_item_code diff --git a/app/models/order.rb b/app/models/order.rb index 72bbf60e..15ce56c3 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -309,9 +309,9 @@ class Order < ApplicationRecord end #Process order items and send to order queue - def self.pay_process_order_queue(id,table_id,sale_id=nil) + def self.pay_process_order_queue(id,table_id) #Send to background job for processing - OrderQueueProcessorJob.perform_later(id, table_id,sale_id) + OrderQueueProcessorJob.perform_later(id, table_id) end def check_cup_status(status) diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index fd7c3420..af544ce5 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -13,16 +13,16 @@ class OrderQueueStation < ApplicationRecord # validations validates_presence_of :station_name, :printer_name - def process_order (order, table_id,sale_id=nil) + def process_order (order, table_id) oqs_stations = OrderQueueStation.active order_items = order.order_items - if table_id > 0 + if table_id.to_i > 0 # get dining - dining=DiningFacility.find(table_id) + dining = DiningFacility.find(table_id) oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}") booking = Booking.find_by_dining_facility_id(dining.id) @@ -46,10 +46,10 @@ class OrderQueueStation < ApplicationRecord # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) # else - # if (order_item.price != 0) + if (order_item.qty > 0) AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs) oqs_order_items.push(order_item) - # end + end # end end end @@ -64,46 +64,38 @@ class OrderQueueStation < ApplicationRecord end end else - # get dining - sale = Sale.find(sale_id).shift_sale_id - terminal_by_zones = CashierTerminalByZones.where("cashier_terminal_id=#{shift.cashier_terminal_id}") - - # ToDo per item per printer - terminal_by_zones.each do |tbz| - OrderQueueProcessByZone.where("zone_id=#{tbz.zone_id}").find_each do |oqpbz| - oqs = OrderQueueStation.find(oqpbz.order_queue_station_id) - is_auto_printed = false - oqs_order_items = [] + oqs_stations.each do |oqs| + is_auto_printed = false + oqs_order_items = [] - if oqs.is_active - #Get List of items - - pq_items = JSON.parse(oqs.processing_items) - #Loop through the processing items - pq_items.each do |pq_item| - #Processing through the looping items - order_items.each do |order_item| - if (pq_item == order_item.item_code) - # if oqs.id == oqpbz.order_queue_station_id - # #Same Order_items can appear in two location. - # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) - # else - - # if (order_item.price != 0) - AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs) - oqs_order_items.push(order_item) - # end - # end - end + if oqs.is_active + #Get List of items - + pq_items = JSON.parse(oqs.processing_items) + #Loop through the processing items + pq_items.each do |pq_item| + #Processing through the looping items + order_items.each do |order_item| + if (pq_item == order_item.item_code) + # if oqs.id == oqpbz.order_queue_station_id + # #Same Order_items can appear in two location. + # AssignedOrderItem.assigned_order_item(order, order_item.item_code, oqs) + # else + + if (order_item.qty > 0) + AssignedOrderItem.assigned_order_item(order, order_item.item_code, order_item.item_instance_code, oqs) + oqs_order_items.push(order_item) + end + # end end end - - if oqs.auto_print - if oqs_order_items.length > 0 - print_slip(oqs, order, oqs_order_items) - is_auto_printed = true - end - end end + + if oqs.auto_print + if oqs_order_items.length > 0 + print_slip(oqs, order, oqs_order_items) + is_auto_printed = true + end + end end end end #end else diff --git a/app/models/print_setting.rb b/app/models/print_setting.rb index b4f17a62..d28b852b 100755 --- a/app/models/print_setting.rb +++ b/app/models/print_setting.rb @@ -3,6 +3,6 @@ class PrintSetting < ApplicationRecord validates_presence_of :name, :unique_code, :printer_name, :page_width, :page_height, :print_copies def self.get_precision_delimiter - PrintSetting.find_by_unique_code("CloseCashierPdf") + PrintSetting.find_by_unique_code("ReceiptBillPdf") end end diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index e62ab4d1..d4817346 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -22,18 +22,44 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # end #Bill Receipt Print - def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount) + # def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges) + # #Use CUPS service + # #Generate PDF + # #Print + # cashier = shift_sale.employee.name + # shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + + # pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges) + # filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" + # pdf.render_file filename + # self.print(filename, cashier_terminal.printer_name) + # end + + def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges) + #Use CUPS service #Generate PDF #Print cashier = shift_sale.employee.name shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") - + filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount) - filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" + close_cashier_pdf = Lookup.collection_of("print_settings") #print_settings with name:CloseCashierPdf + + if !close_cashier_pdf.empty? + close_cashier_pdf.each do |close_cashier| + if close_cashier[0] == 'CloseCashierCustomisePdf' + if close_cashier[1] == '1' + pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges) + else + pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount) + end + end + end + end pdf.render_file filename + self.print(filename, cashier_terminal.printer_name) end - - + #sqa end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index c60fcc35..0cf6526f 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -173,19 +173,19 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker end #Bill Receipt Print - def print_receipt_bill(printer_settings,cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data,survey) + def print_receipt_bill(printer_settings,cashier_terminal,sale_items,sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount=nil,shop_details, printed_status,balance,card_data) #Use CUPS service #Generate PDF #Print - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,survey) + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf if !receipt_bill_a5_pdf.empty? receipt_bill_a5_pdf.each do |receipt_bilA5| if receipt_bilA5[0] == 'ReceiptBillA5Pdf' if receipt_bilA5[1] == '1' - pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,survey) + pdf = ReceiptBillA5Pdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) else - pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data,survey) + pdf = ReceiptBillPdf.new(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info,rebate_amount,shop_details,printed_status,balance,card_data) end end end diff --git a/app/models/product.rb b/app/models/product.rb index 3c915a38..3256fe17 100755 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -5,11 +5,18 @@ class Product < ApplicationRecord mount_uploader :image_path, ProductImageUploader def self.search_by_product_code(item_code) + account = Account.find_by_title('Product') + if !account.nil? + account_id = account.id + else + account_id = 1 + end + menu_item_hash = Hash.new mt_instance = Product.find_by_item_code(item_code) if (!mt_instance.nil?) menu_item_hash[:type] = 'Product' - menu_item_hash[:account_id] = 1 + menu_item_hash[:account_id] = account_id menu_item_hash[:item_code] = mt_instance.item_code menu_item_hash[:item_instance_code] = mt_instance.item_code menu_item_hash[:name] = mt_instance.name.to_s diff --git a/app/models/sale.rb b/app/models/sale.rb index f381ba39..54c60eb3 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -92,7 +92,11 @@ class Sale < ApplicationRecord self.cashier_id = open_cashier[0].id self.cashier_name = open_cashier[0].name shift_id = ShiftSale.current_open_shift(open_cashier[0].id) - self.shift_sale_id = shift_id.id + if shift_id + self.shift_sale_id = shift_id.id + else + self.shift_sale_id = current_shift.id + end else self.cashier_id = current_shift.employee_id self.cashier_name = Employee.find(current_shift.employee_id).name @@ -227,7 +231,7 @@ class Sale < ApplicationRecord sale_item.product_name = item.item_name sale_item.product_alt_name = item.alt_name sale_item.account_id = item.account_id - sale_item.remark = item.remark + sale_item.status = item.remark sale_item.qty = item.qty sale_item.unit_price = item.price @@ -255,7 +259,7 @@ class Sale < ApplicationRecord sale_item.product_name = instance.item_instance_name sale_item.product_alt_name = menu_item.alt_name sale_item.account_id = menu_item.account_id - sale_item.remark = nil + sale_item.status = nil sale_item.qty = item["quantity"] sale_item.unit_price = item["price"] @@ -381,7 +385,7 @@ class Sale < ApplicationRecord rounding_adjustment = 0 sales_items.each do |item| - if item.remark != 'void' && item.remark != 'foc' + if item.status != 'void' && item.status != 'foc' #compute each item and added to total subtotal_price = subtotal_price + item.price @@ -417,35 +421,36 @@ class Sale < ApplicationRecord tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(sale.customer_id) # #Creat new tax records - tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax.to_i == tax.id - sale_tax = SaleTax.new(:sale => sale) - sale_tax.tax_name = tax.name - sale_tax.tax_rate = tax.rate + if sale.payment_status != 'foc' + tax_profiles.each do |tax| + customer.tax_profiles.each do |cus_tax| + if cus_tax.to_i == tax.id + sale_tax = SaleTax.new(:sale => sale) + sale_tax.tax_name = tax.name + sale_tax.tax_rate = tax.rate - # substract , to give after discount - total_tax = total_taxable - total_discount - #include or execulive - if tax.inclusive - rate = tax.rate - divided_value = (100 + rate)/rate - sale_tax.tax_payable_amount = total_tax / divided_value - else - sale_tax.tax_payable_amount = total_tax * tax.rate / 100 - total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount - end - #new taxable amount is standard rule for step by step - if shop.calc_tax_order - total_taxable = total_taxable + sale_tax.tax_payable_amount - end + # substract , to give after discount + total_tax = total_taxable - total_discount + #include or execulive + if tax.inclusive + rate = tax.rate + divided_value = (100 + rate)/rate + sale_tax.tax_payable_amount = total_tax / divided_value + else + sale_tax.tax_payable_amount = total_tax * tax.rate / 100 + total_tax_amount = total_tax_amount + sale_tax.tax_payable_amount + end + #new taxable amount is standard rule for step by step + if shop.calc_tax_order + total_taxable = total_taxable + sale_tax.tax_payable_amount + end - sale_tax.inclusive = tax.inclusive - sale_tax.save + sale_tax.inclusive = tax.inclusive + sale_tax.save + end end end end - sale.total_tax = total_tax_amount end @@ -757,7 +762,7 @@ end def self.get_item_query() query = Sale.select("acc.title as account_name,mi.account_id, i.item_instance_code as item_code,i.account_id as account_id, " + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item,i.qty as qty," + - "i.remark as status_type,"+ + "i.status as status_type,"+ " i.unit_price,i.price as price,i.product_name as product_name, mc.name as" + " menu_category_name,mc.id as menu_category_id ") @@ -776,7 +781,7 @@ end def self.get_other_charges() query = Sale.select("i.account_id as account_id, " + "SUM(i.qty * i.unit_price) as grand_total,SUM(i.qty) as total_item," + - "i.remark as status_type,"+ + "i.status as status_type,"+ " i.unit_price as unit_price,i.product_name as product_name") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id") query = query.where("i.item_instance_code IS NULL AND i.product_code = 'Other Charges'") @@ -785,7 +790,6 @@ end def self.get_by_shift_items(shift_sale_range, shift, from, to, status) # date_type_selection = get_sql_function_for_report_type(report_type) - query = self.get_item_query() discount_query = 0 @@ -861,6 +865,29 @@ def self.get_by_shift_items(shift_sale_range, shift, from, to, status) return query,other_charges, discount_query , total_cash_amount , total_card_amount , total_credit_amount , total_foc_amount , total_grand_total , change_amount end +#product sale report query +def self.get_menu_item_query(order_by) + query = MenuItem.unscoped.select("acc.id as account_id, + acc.title as account_name, + mii.item_instance_code as item_code, " + + "(CASE WHEN si.qty IS NOT NULL THEN SUM(si.qty) ELSE 0 END) as total_item," + + "(CASE WHEN si.unit_price != mii.price THEN si.unit_price ELSE mii.price END) as unit_price," + + "(CASE WHEN si.qty IS NOT NULL THEN (SUM(si.qty) * si.unit_price) ELSE 0 END) as grand_total," + + "mii.price as unit_price, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE mii.item_instance_name END) as product_name, + mc.name as" + + " menu_category_name,mc.id as menu_category_id, si.remark as status_type, + si.price as price ") + .joins(" LEFT JOIN menu_item_instances mii ON menu_items.id = mii.menu_item_id" + + " LEFT JOIN menu_categories mc ON mc.id = menu_items.menu_category_id" + + " LEFT JOIN accounts acc ON acc.id = menu_items.account_id" + + " LEFT JOIN sale_items si ON si.item_instance_code = mii.item_instance_code" + + " LEFT JOIN sales s ON s.sale_id = si.sale_id") + .where("(CASE WHEN s.sale_status IS NOT NULL THEN s.sale_status='completed' ELSE 1 END)") + .group("mc.id, (CASE WHEN si.product_name IS NOT NULL THEN si.product_name ELSE mii.item_instance_name END)") + .order("si.qty #{order_by}, menu_items.menu_category_id #{order_by}") +end +#product sale report query + def self.get_shift_sales_by_receipt_no(shift_sale_range,shift,from,to,payment_type) ## => left join -> show all sales although no orders if payment_type.blank? @@ -1068,95 +1095,376 @@ end return tax end - def self.top_products(today) - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + def self.top_products(today,from,to) + if !from.nil? && !to.nil? + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + .where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+ + "and payment_status='paid' and sale_status= 'completed'") + .group('mi.name') + .order("SUM(i.qty) DESC").limit(20) + else + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ "and payment_status='paid' and sale_status= 'completed'") .group('mi.name') - .order("SUM(i.qty) DESC").limit(10) + .order("SUM(i.qty) DESC").limit(20) + end end - def self.bottom_products(today) - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + def self.bottom_products(today,from,to) + if !from.nil? && !to.nil? + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + " i.price as unit_price,mi.name as product_name") + .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") + .where("(i.qty > 0 and i.price > 0) and receipt_date between '#{from}' and '#{to}'"+ + "and payment_status='paid' and sale_status= 'completed'") + .group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + else + query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + " i.price as unit_price,mi.name as product_name") .joins("JOIN sale_items i ON i.sale_id = sales.sale_id JOIN menu_items mi ON i.product_code = mi.item_code") .where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ "and payment_status='paid' and sale_status= 'completed'") .group('mi.name') - .order("SUM(i.qty) ASC").limit(10) + .order("SUM(i.qty) ASC").limit(20) + end end - def self.hourly_sales(today) - query= Sale.select("grand_total") + def self.hourly_sales(today,from,to) + if !from.nil? && !to.nil? + query= Sale.select("grand_total") + .where('payment_status="paid" and sale_status = "completed" and receipt_date between ? and ?',from,to) + .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .order('receipt_date') + else + query= Sale.select("grand_total") .where('payment_status="paid" and sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") .order('receipt_date') + end end - def self.employee_sales(today) - query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") + def self.employee_sales(today,from,to) + if !from.nil? && !to.nil? + query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") + .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") + .where("sales.payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between '#{from}' and '#{to}'") + .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name") + .order("e.name") + else + query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") .joins("JOIN sale_payments as sp on sp.sale_id=sales.sale_id") .where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = '#{today}'") .group("(CASE WHEN (sp.payment_method='mpu' or sp.payment_method='visa' or sp.payment_method='master' or sp.payment_method='jcb' or sp.payment_method='unionpay') THEN 'card' ELSE sp.payment_method END)","e.name") .order("e.name") + end end - def self.total_sale(today) - total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total") - - end - - def self.total_count(today) - total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count - end - - def self.total_card_sale(today) - payment_type = " and payment_method = 'mpu' or payment_method = 'visa' or payment_method = 'master' or payment_method = 'jcb' or payment_method = 'unionpay' " - # query = Sale.select("SUM(tax_payable_amount) AS st_amount,tax_name") - # .where('sale_status = "completed" #{payment_type} and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) - # .joins("join sale_payments on sale_id = sales.sale_id") - # .group("sales.sale_id") - - query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today) - .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") - .sum("sp.payment_amount") - - end - - def self.credit_payment(today) - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today) - .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") - .sum("payment_amount") - end - - def self.summary_sale_receipt(today) - query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') - .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) - .first() - end - - def self.total_payment_methods(today) - query = Sale.select("distinct sp.payment_method") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) - .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") - end - - def self.payment_sale(payment_method, today) - query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") - if payment_method == 'card' - query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today) - else - query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + def self.total_sale(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total") + else + if current_user.role == 'administrator' + total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + total = Sale.where('sale_status = "completed" and sales.receipt_date between ? and ? and shift_sale_id=?',from,to,shift.id) + .sum("grand_total") end - query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + end + end + else + if current_user.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total") + else + if current_user.role == 'administrator' + total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).sum("grand_total") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) + .sum("grand_total") + end + end + end + end end - def self.total_customer(today) - dinein_cnt = self.total_dinein(today) - takeaway_cnt = self.total_takeaway(today) - membership_cnt = self.total_membership(today) + def self.total_count(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count + else + if current_user.role == 'administrator' + total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + total = Sale.where('sale_status = "completed" and receipt_date between ? and ? and shift_sale_id = ?',from,to,shift.id).count + end + end + end + else + if current_user.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count + else + if current_user.role == 'administrator' + total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today).count + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id = ?',today,shift.id).count + end + end + end + end + end + + def self.total_card_sale(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + else + if current_user.role == 'administrator' + query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and shift_sale_id=?',from,to,shift.id) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + end + end + end + else + if current_user.nil? + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + else + if current_user.role == 'administrator' + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and shift_sale_id=?',today,shift.id) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + end + end + end + end + end + + def self.credit_payment(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ?',from,to) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + else + if current_user.role == 'administrator' + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ?',from,to) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ? and s.shift_sale_id=?',from,to,shift.id) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + end + end + end + else + if current_user.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + else + if current_user.role == 'administrator' + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ?',today) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(s.receipt_date,"%Y-%m-%d") = ? and s.shift_sale_id=?',today,shift.id) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + end + end + end + end + end + + def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and receipt_date between ? and ?',from,to) + .first() + else + if current_user.role == 'administrator' + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and receipt_date between ? and ?',from,to) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and receipt_date between ? and ? and shift_sale_id=?',from,to,shift.id) + .first() + end + end + end + else + if current_user.nil? + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) + .first() + else + if current_user.role == 'administrator' + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ?',today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select('count(sale_id) as total_receipt, (case when sum(total_amount) > 0 then sum(total_amount) else 0.0 end) as total_amount, (case when sum(grand_total) > 0 then sum(grand_total) else 0.0 end) as grand_total, (case when sum(total_discount) > 0 then sum(total_discount) else 0.0 end) as total_discount, (case when sum(total_tax) > 0 then sum(total_tax) else 0.0 end) as total_tax') + .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) + .first() + end + end + end + end + end + + def self.total_payment_methods(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + if current_user.role == 'administrator' + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + end + end + end + else + if current_user.nil? + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + if current_user.role == 'administrator' + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + end + end + end + end + end + + def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + else + if current_user.role == 'administrator' + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',from,to) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and sales.shift_sale_id=?',from,to,shift.id) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + end + end + end + else + if current_user.nil? + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + else + if current_user.role == 'administrator' + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay")',today) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + if payment_method == 'card' + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and (sp.payment_method = "mpu" or sp.payment_method = "visa" or sp.payment_method = "master" or sp.payment_method = "jcb" or sp.payment_method = "unionpay") and sales.shift_sale_id=?',today,shift.id) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) + end + query.select("(CASE WHEN sp.payment_method='cash' THEN (SUM(sp.payment_amount) - SUM(sales.amount_changed)) ELSE SUM(sp.payment_amount) END) as payment_amount").first() + end + end + end + end + end + + def self.total_customer(today,current_user=nil,from=nil,to=nil) + dinein_cnt = self.total_dinein(today,current_user,from,to) + takeaway_cnt = self.total_takeaway(today,current_user,from,to) + membership_cnt = self.total_membership(today,current_user,from,to) total_cus = 0 if !dinein_cnt.nil? || !takeaway_cnt.nil? || !membership_cnt.nil? @@ -1166,69 +1474,448 @@ end return total_cus end - def self.total_dinein(today) - query = Sale.select("count(sales.customer_id) as total_dinein_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) - .first() + def self.total_dinein(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.select("count(sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) + .first() + end + end + end + else + if current_user.nil? + query = Sale.select("count(sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null',today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(sales.customer_id) as total_dinein_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) + .first() + end + end + end + end end - def self.total_takeaway(today) - query = Sale.select("count(sales.customer_id) as total_take_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) - .first() + def self.total_takeaway(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) + .first() + end + end + end + else + if current_user.nil? + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null',today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(sales.customer_id) as total_take_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) + .first() + end + end + end + end end - def self.total_membership(today) - query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today) - .first() + def self.total_membership(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',from,to) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',from,to,shift.id) + .first() + end + end + end + else + if current_user.nil? + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null))',today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(distinct sales.customer_id) as total_memb_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and ((c.customer_type = "Dinein" and c.membership_id is not null) or (c.customer_type = "Takeaway" and c.membership_id is not null)) and sales.shift_sale_id=?',today,shift.id) + .first() + end + end + end + end end - def self.total_other_customer(today) - query = Sale.select("count(sales.customer_id) as total_cus") - .joins("JOIN customers as c ON c.customer_id = sales.customer_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) - .first() + def self.total_other_customer(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.select("count(sales.customer_id) as total_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(sales.customer_id) as total_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null',from,to) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(sales.customer_id) as total_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,shift.id) + .first() + end + end + end + else + if current_user.nil? + query = Sale.select("count(sales.customer_id) as total_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(sales.customer_id) as total_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null',today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(sales.customer_id) as total_cus") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',today,shift.id) + .first() + end + end + end + end end - def self.total_order(today) - query = Sale.select("count(distinct a.order_id) as total_order") - .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") - .joins("JOIN orders as b ON b.order_id = a.order_id") - .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) - .first() + def self.total_order(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.select("count(distinct a.order_id) as total_order") + .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") + .joins("JOIN orders as b ON b.order_id = a.order_id") + .where('b.status = "billed" and sales.receipt_date between ? and ?',from,to) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(distinct a.order_id) as total_order") + .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") + .joins("JOIN orders as b ON b.order_id = a.order_id") + .where('b.status = "billed" and sales.receipt_date between ? and ?',from,to) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(distinct a.order_id) as total_order") + .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") + .joins("JOIN orders as b ON b.order_id = a.order_id") + .where('b.status = "billed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id) + .first() + end + end + end + else + if current_user.nil? + query = Sale.select("count(distinct a.order_id) as total_order") + .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") + .joins("JOIN orders as b ON b.order_id = a.order_id") + .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(distinct a.order_id) as total_order") + .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") + .joins("JOIN orders as b ON b.order_id = a.order_id") + .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(distinct a.order_id) as total_order") + .joins("JOIN sale_orders as a ON a.sale_id = sales.sale_id") + .joins("JOIN orders as b ON b.order_id = a.order_id") + .where('b.status = "billed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) + .first() + end + end + end + end end - def self.total_account(today) - query = Sale.select("distinct b.id as account_id, b.title as title") - .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .joins("JOIN accounts as b ON b.id = a.account_id") - .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + def self.total_account(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.select("distinct b.id as account_id, b.title as title") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .joins("JOIN accounts as b ON b.id = a.account_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) + else + if current_user.role == 'administrator' + query = Sale.select("distinct b.id as account_id, b.title as title") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .joins("JOIN accounts as b ON b.id = a.account_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("distinct b.id as account_id, b.title as title") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .joins("JOIN accounts as b ON b.id = a.account_id") + .where('sales.sale_status = "completed" and sales.receipt_date between ? and ? and sales.shift_sale_id=?',from,to,shift.id) + end + end + end + else + if current_user.nil? + query = Sale.select("distinct b.id as account_id, b.title as title") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .joins("JOIN accounts as b ON b.id = a.account_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + else + if current_user.role == 'administrator' + query = Sale.select("distinct b.id as account_id, b.title as title") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .joins("JOIN accounts as b ON b.id = a.account_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ?',today) + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("distinct b.id as account_id, b.title as title") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .joins("JOIN accounts as b ON b.id = a.account_id") + .where('sales.sale_status = "completed" and DATE_FORMAT(sales.receipt_date,"%Y-%m-%d") = ? and sales.shift_sale_id=?',today,shift.id) + end + end + end + end end - def self.account_data(account_id, today) - query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") - .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - .first() + def self.account_data(account_id, today, current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ?",from,to) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + .first() + end + end + end + else + if current_user.nil? + query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .first() + else + if current_user.role == 'administrator' + query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("count(*) as cnt_acc, SUM(a.price) as total_acc") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) + .first() + end + end + end + end end - def self.top_items(today) - query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") - .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - .group("a.product_code") - .order("SUM(a.qty) DESC") - .first() + def self.top_items(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ?",from,to) + .group("a.product_code") + .order("SUM(a.qty) DESC") + .first() + else + if current_user.role == 'administrator' + query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ?",from,to) + .group("a.product_code") + .order("SUM(a.qty) DESC") + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + .group("a.product_code") + .order("SUM(a.qty) DESC") + .first() + end + end + end + else + if current_user.nil? + query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .group("a.product_code") + .order("SUM(a.qty) DESC") + .first() + else + if current_user.role == 'administrator' + query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .group("a.product_code") + .order("SUM(a.qty) DESC") + .first() + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("a.product_name as item_name, SUM(a.price) as item_total_price") + .joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) + .group("a.product_code") + .order("SUM(a.qty) DESC") + .first() + end + end + end + end end - def self.total_foc_items(today) - query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") - .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) - .sum("a.qty") + def self.total_foc_items(today,current_user=nil,from=nil,to=nil) + if !from.nil? && !to.nil? + if current_user.nil? + query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ?",from,to) + .sum("a.qty") + else + if current_user.role == 'administrator' + query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ?",from,to) + .sum("a.qty") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and sales.receipt_date between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + .sum("a.qty") + end + end + end + else + if current_user.nil? + query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .sum("a.qty") + else + if current_user.role == 'administrator' + query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ?",today) + .sum("a.qty") + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.joins("JOIN sale_items as a ON a.sale_id = sales.sale_id") + .where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(sales.receipt_date,'%Y-%m-%d') = ? and sales.shift_sale_id=?",today,shift.id) + .sum("a.qty") + end + end + end + end end #card sale trans data @@ -1310,12 +1997,19 @@ end end end - def self.pending_order + def self.pending_sale query = Sale.all query = query.joins("join sale_orders as sale_orders on sale_orders.sale_id = sales.sale_id") .joins("join orders as orders on orders.order_id = sale_orders.order_id") query = query.where("sales.sale_status = 'new' AND orders.status = 'billed' AND orders.source =? ","quick_service") end + def self.pending_order + query = Booking.all + query = query.joins("join booking_orders as booking_orders on booking_orders.booking_id = bookings.booking_id") + .joins("join orders as orders on orders.order_id = booking_orders.order_id") + query = query.where("bookings.booking_status = 'assign' AND orders.status = 'new' AND orders.source =? ","quick_service") + .group("bookings.booking_id") + end private diff --git a/app/models/sale_audit.rb b/app/models/sale_audit.rb index 55541851..633db6fe 100755 --- a/app/models/sale_audit.rb +++ b/app/models/sale_audit.rb @@ -24,9 +24,9 @@ class SaleAudit < ApplicationRecord sale_audit.sale_id = sale_id sale_audit.action = "SALECOMPLETE" sale_audit.action_at = DateTime.now.utc - sale_audit.action_by = action_by + sale_audit.action_by = Sale.find(sale_id).cashier_id sale_audit.remark = remark - sale_audit.approved_by = Time.now + sale_audit.approved_by = action_by sale_audit.save! end @@ -72,9 +72,9 @@ class SaleAudit < ApplicationRecord sale_audit.sale_id = sale_id sale_audit.action = "SALEPAYMENT" sale_audit.action_at = DateTime.now.utc - sale_audit.action_by = action_by + sale_audit.action_by = Sale.find(sale_id).cashier_id sale_audit.remark = remark - sale_audit.approved_by = Time.now + sale_audit.approved_by = action_by sale_audit.save! end @@ -83,9 +83,9 @@ class SaleAudit < ApplicationRecord sale_audit.sale_id = sale_id sale_audit.action = "PAYMAL" sale_audit.action_at = DateTime.now.utc - sale_audit.action_by = action_by + sale_audit.action_by = Sale.find(sale_id).cashier_id sale_audit.remark = remark - sale_audit.approved_by = Time.now + sale_audit.approved_by = action_by sale_audit.save! end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index 465af104..64e0ec73 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -28,7 +28,7 @@ class SaleItem < ApplicationRecord def self.update_existing_item(qty, item, sale_id, type, item_price, price) # Original Item to add remark - item.remark = type + item.status = type item.save sale_item = SaleItem.new @@ -37,7 +37,7 @@ class SaleItem < ApplicationRecord sale_item.product_name = item.product_name + " (#{type.upcase})" sale_item.product_alt_name = item.product_alt_name sale_item.account_id = item.account_id - sale_item.remark = type + sale_item.status = type if type == "foc" || type == "promotion" || type == "void" sale_item.qty = qty * (-1) else @@ -99,7 +99,7 @@ class SaleItem < ApplicationRecord discount_account = {:name => a.title, :price => 0} # Check for actual sale items - sale_items.where("remark = 'Discount'").find_each do |si| + sale_items.where("status = 'Discount'").find_each do |si| if si.account_id == a.id discount_account[:price] = (discount_account[:price].abs + si.price.abs) * (1) end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index c2fce169..bb74c2f2 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -8,7 +8,7 @@ class SalePayment < ApplicationRecord attr_accessor :received_amount, :card_payment_reference, :voucher_no, :giftcard_no, :customer_id, :external_payment_status - def process_payment(invoice, action_by, cash_amount, payment_method) + def process_payment(invoice, action_by, cash_amount, payment_method,remark=nil) self.sale = invoice self.received_amount = cash_amount amount_due = invoice.grand_total @@ -53,7 +53,7 @@ class SalePayment < ApplicationRecord end #record an payment in sale-audit - remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}" + # remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}" sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by) # update complete order items in oqs @@ -67,7 +67,7 @@ class SalePayment < ApplicationRecord return true, self.save else #record an payment in sale-audit - remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" + # remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by) return false, "No outstanding Amount" @@ -194,7 +194,7 @@ class SalePayment < ApplicationRecord payment_status = false # add to sale item with foc - sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }' and remark is null") + sale_items = SaleItem.where("sale_id='#{ self.sale.sale_id }' and status is null") sale_items.each do|item| SaleItem.update_existing_item(item.qty, item, self.sale.sale_id, "foc", item.unit_price, item.price) diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 57816948..10b2de38 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -135,6 +135,27 @@ class ShiftSale < ApplicationRecord end + def self.get_total_dinein(shift) + query = Sale.select("sum(sales.grand_total) as total_dinein_amount") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Dinein" and c.membership_id is null',shift.id) + .first() + end + + def self.get_total_takeway(shift) + query = Sale.select("sum(sales.grand_total) as total_takeway_amount") + .joins("JOIN customers as c ON c.customer_id = sales.customer_id") + .where('shift_sale_id =? and sales.sale_status = "completed" and c.customer_type = "Takeaway" and c.membership_id is null',shift.id) + .first() + end + + def self.get_total_other_charges(shift) + query = SaleItem.select("sum(sale_items.qty * sale_items.unit_price) as total_other_charges_amount") + .joins("JOIN sales as s ON s.sale_id = sale_items.sale_id") + .where('shift_sale_id =? and s.sale_status = "completed" and sale_items.product_code = "Other Charges" and sale_items.item_instance_code is null',shift.id) + .first() + end + def self.search(filter,from,to) if filter.blank? keyword = '' diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index 35bebca2..c2a12f4a 100755 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -36,12 +36,20 @@ class StockJournal < ApplicationRecord journal.save end - def self.inventory_balances(today) - query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") + def self.inventory_balances(today,from,to) + if !from.nil? && !to.nil? + query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") + .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") + .where("stock_journals.created_at between '#{from}' and '#{to}'") + .group("mii.item_instance_name") + .order("mii.item_instance_name ASC") + else + query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") .joins("join menu_item_instances mii on mii.item_instance_code=stock_journals.item_code") .where("DATE_FORMAT(stock_journals.created_at,'%Y-%m-%d') = '#{today}'") .group("mii.item_instance_name") .order("mii.item_instance_name ASC") + end end end diff --git a/app/pdf/close_cashier_customise_pdf.rb b/app/pdf/close_cashier_customise_pdf.rb new file mode 100644 index 00000000..bcc27724 --- /dev/null +++ b/app/pdf/close_cashier_customise_pdf.rb @@ -0,0 +1,496 @@ +class CloseCashierCustomisePdf < Prawn::Document + include ActionView::Helpers::NumberHelper + attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width + + def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges) + self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width + self.page_height = printer_settings.page_height + self.margin = 5 + self.price_width = 60 + self.qty_width = 20 + self.total_width = 40 + self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) + self.item_height = 15 + self.item_description_width = (self.page_width-20) / 2 + self.label_width = 100 + + self.text_width = (self.page_width - 80) - self.price_width / 3 + # @item_width = self.page_width.to_i / 2 + # @qty_width = @item_width.to_i / 3 + # @double = @qty_width * 1.3 + # @half_qty = @qty_width / 2 + #setting page margin and width + super(:margin => [printer_settings.heading_space, self.margin, self.margin, self.margin], :page_size => [self.page_width, self.page_height]) + + # db font setup + if printer_settings.font != "" + font_families.update("#{printer_settings.font}" => { + :normal => "public/fonts/#{printer_settings.font}.ttf", + :italic => "public/fonts/#{printer_settings.font}.ttf", + :bold => "public/fonts/#{printer_settings.font}.ttf", + :bold_italic => "public/fonts/#{printer_settings.font}.ttf" + }) + + font "#{printer_settings.font}" + fallback_fonts ["Courier", "Helvetica", "Times-Roman"] + end + # font "public/fonts/Zawgyi-One.ttf" + # font "public/fonts/padauk.ttf" + self.header_font_size = 10 + self.item_font_size = 8 + + #precision checked + if printer_settings.precision.to_i > 2 + printer_settings.precision = 2 + end + #check delimiter + if printer_settings.delimiter + delimiter = "," + else + delimiter = "" + end + + header( shop_details) + + stroke_horizontal_rule + + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_dinein,total_takeway,total_other_charges) + end + + def header (shop_details) + move_down 7 + text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center + move_down 5 + text "#{shop_details.address}", :size => self.item_font_size,:align => :center + # move_down self.item_height + move_down 5 + text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center + move_down 5 + + stroke_horizontal_rule + end + + def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_dinein,total_takeway,total_other_charges) + move_down 7 + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Cashier : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.employee.name}" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Cashier Station : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.cashier_terminal.name}" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Opening Date : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.shift_started_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Closing Date : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ shift_sale.shift_closed_at.utc.getlocal.strftime('%d-%m-%Y %I:%M %p') }" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Opening Float : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ number_with_precision(shift_sale.opening_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do + text "Closing Float : ", :size => self.item_font_size,:align => :left + end + bounding_box([self.label_width,y_position], :width => self.label_width, :height => self.item_height) do + text "#{ number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :left + # text_box "#{number_with_precision(total_price, :precision => precision.to_i, :delimiter => delimiter)}" + end + + + move_down 10 + + y_position = cursor + bounding_box([0,y_position], :width =>self.page_width - 10, :height => 20) do + text "Shift Sale Summary", :size => self.header_font_size, :align => :center + end + move_down 10 + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Received Amount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(shift_sale.closing_balance, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Cash In :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(shift_sale.cash_in, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Cash Out :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(shift_sale.cash_out, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + move_down -5 + stroke_horizontal_rule + move_down 7 + + #start total amount by Account Like Food / Beverage /.. + total_discount_account = 0 + total_discount_by_account.each do |amount| + + total_discount_account = total_discount_account.to_f + amount.total_price.to_f + end + #end total amount by Account + + #start total FOC amount + @total_foc = 0 + other_payment.each do |other| + @total_foc = other.foc_amount.round(2) + end + + #end total FOC amount + total_grand_total = shift_sale.grand_total + @total_foc.to_f + shift_sale.total_void.to_f - total_discount_account.to_f + # @total_grand_total = @shift_sale.grand_total + @overall + @total_foc + @shift_sale.total_void + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Grand Total :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(total_grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + #start total amount by Account Like Food / Beverage /.. + total_discount_by_account.each do |amount| + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + end + end + #end total amount by Account + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total FOC :", :size => self.item_font_size, :align => :right + end + if @total_foc.nil? + @total_foc = 0 + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "(#{ number_with_precision(@total_foc, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Void :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "(#{shift_sale.total_void})", :size => self.item_font_size, :align => :right + end + + move_down -5 + stroke_horizontal_rule + move_down 7 + + @total_foc = 0 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Cash Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(shift_sale.cash_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Credit Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(shift_sale.credit_sales, :precision => precision.to_i, :delimiter => delimiter) }", :size => self.item_font_size, :align => :right + end + #start other payment details + if shift_sale.other_sales > 0 + other_payment.each do |other| + @total_foc = other.foc_amount.round(2) + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "MPU Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(other.mpu_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "VISA Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(other.visa_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Master Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(other.master_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "JCB Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(other.jcb_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # text "Reedem Payment :", :size => self.item_font_size, :align => :right + # end + # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + # text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + # end + end + else + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Other Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(shift_sale.other_sales, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Rounding Adjustments :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(shift_sale.total_rounding, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Gross Sale :", :style => :bold, :size => self.header_font_size - 1, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(shift_sale.grand_total, :precision => precision.to_i, :delimiter => delimiter)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + end + + # end other payment details + move_down -5 + stroke_horizontal_rule + move_down 7 + + # start Dinein and Takeaway + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Dinein :", :size => self.item_font_size, :align => :right + end + if total_dinein.nil? + total_dinein = 0 + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(total_dinein, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Takeaway :", :size => self.item_font_size, :align => :right + end + if total_takeway.nil? + total_takeway = 0 + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(total_takeway, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + + # stop Dinein and Takeaway + move_down -5 + stroke_horizontal_rule + move_down 7 + + #start service charges and commercial tax + sale_taxes.each do |tax| + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(tax.st_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Taxes :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(shift_sale.total_taxes, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right + end + #end for service charges and commercial tax +#COMMENTED FOR NO NEED AND NOT CORRECT WHEN OTHER CHARGES + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # text "Total Sale :", :size => self.item_font_size, :align => :right + # end + # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + # text "#{shift_sale.total_revenue}", :size => self.item_font_size, :align => :right + # end + + move_down -5 + stroke_horizontal_rule + move_down 7 + #start total amount by Account Like Food / Beverage /.. + # total_discount_by_account.each do |amount| + + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # text "Total #{amount.account_name} Discount:", :size => self.item_font_size, :align => :right + # end + # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + # text "#{ number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + # end + # end + #end total amount by Account + + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # text "Grand Total :", :size => self.item_font_size, :align => :right + # end + # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right + # end + + + #start total amount by Account Like Food / Beverage /.. + total_amount_by_account.each do |amount| + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{number_with_precision(amount.total_price, :precision => precision.to_i, :delimiter => delimiter)} ", :size => self.item_font_size, :align => :right + end + end + #end total amount by Account + + #start total other charges amount + if total_other_charges.present? + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Other Charges :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(total_other_charges, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + end + #end total other charges amount + + move_down -5 + stroke_horizontal_rule + move_down 7 + + #start total over all discount + if total_member_discount[0].member_discount.present? + @member_discount = total_member_discount[0].member_discount rescue 0.0 + @overall = shift_sale.total_discounts - @member_discount + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Member Discount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(@member_discount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + else + @overall = shift_sale.total_discounts + end + + if @overall > 0 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Overall Discount :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "-#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + move_down -5 + stroke_horizontal_rule + move_down 7 + end + #end total over all discount + + + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Dine-in Count :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{shift_sale.dining_count}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Takeaway Count :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{shift_sale.takeaway_count}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Receipts :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{shift_sale.total_receipt}", :size => self.item_font_size, :align => :right + end + + move_down 5 + stroke_horizontal_rule + move_down 5 + move_down 5 + end +end + diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 35248b97..7ac7a130 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -213,7 +213,7 @@ class CloseCashierPdf < Prawn::Document y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Reedem Payment :", :size => self.item_font_size, :align => :right + text "Redeem Payment :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{ number_with_precision(other.paypar_amount, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right @@ -392,7 +392,6 @@ class CloseCashierPdf < Prawn::Document move_down 5 stroke_horizontal_rule move_down 5 - move_down 5 + move_down 5 end -end - +end \ No newline at end of file diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index 26253b6e..379e919c 100755 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -37,8 +37,12 @@ class OrderItemPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" #font "public/fonts/Chinese.ttf" - - text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + if order_item.dining.to_i > 0 + text "#{ order_item.type + '-' + order_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + stroke_horizontal_rule move_down 3 diff --git a/app/pdf/order_item_slim_pdf.rb b/app/pdf/order_item_slim_pdf.rb index f419f185..09cce4d1 100644 --- a/app/pdf/order_item_slim_pdf.rb +++ b/app/pdf/order_item_slim_pdf.rb @@ -37,8 +37,12 @@ class OrderItemSlimPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" #font "public/fonts/Chinese.ttf" - - text "#{ order_item_slim.type + '-' + order_item_slim.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + if order_item_slim.dining.to_i > 0 + text "#{ order_item_slim.type + '-' + order_item_slim.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + stroke_horizontal_rule move_down 1 diff --git a/app/pdf/order_set_item_pdf.rb b/app/pdf/order_set_item_pdf.rb index 8f915ad0..6aa6efc4 100644 --- a/app/pdf/order_set_item_pdf.rb +++ b/app/pdf/order_set_item_pdf.rb @@ -37,8 +37,11 @@ class OrderSetItemPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" #font "public/fonts/Chinese.ttf" - - text "#{ order_set_item.type + '-' + order_set_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + if order_set_item.dining.to_i > 0 + text "#{ order_set_item.type + '-' + order_set_item.dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end stroke_horizontal_rule move_down 3 diff --git a/app/pdf/order_summary_pdf.rb b/app/pdf/order_summary_pdf.rb index 5211061e..6c8dacac 100755 --- a/app/pdf/order_summary_pdf.rb +++ b/app/pdf/order_summary_pdf.rb @@ -36,8 +36,12 @@ class OrderSummaryPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - - text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + if order[0].dining.to_i > 0 + text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + stroke_horizontal_rule move_down 5 diff --git a/app/pdf/order_summary_set_pdf.rb b/app/pdf/order_summary_set_pdf.rb index 619b81ab..8828ea43 100644 --- a/app/pdf/order_summary_set_pdf.rb +++ b/app/pdf/order_summary_set_pdf.rb @@ -36,8 +36,12 @@ class OrderSummarySetPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - - text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + if order[0].dining.to_i > 0 + text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + stroke_horizontal_rule move_down 5 diff --git a/app/pdf/order_summary_slim_pdf.rb b/app/pdf/order_summary_slim_pdf.rb index b4b850fa..73023278 100644 --- a/app/pdf/order_summary_slim_pdf.rb +++ b/app/pdf/order_summary_slim_pdf.rb @@ -36,8 +36,12 @@ class OrderSummarySlimPdf < Prawn::Document # font "public/fonts/Zawgyi-One.ttf" # font "public/fonts/padauk.ttf" - - text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + if order[0].dining.to_i > 0 + text "#{ order[0].type + '-' + order[0].dining + print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + else + text "#{ print_status }", :size => self.header_font_size,:align => :center, :left_margin => -20 + end + stroke_horizontal_rule move_down 1 diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 4851aa0a..fbe28541 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -1,5 +1,6 @@ class ReceiptBillA5Pdf < Prawn::Document include ActionView::Helpers::NumberHelper + attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,survey) self.page_width = printer_settings.page_width @@ -81,8 +82,8 @@ class ReceiptBillA5Pdf < Prawn::Document end #start for individual payment - if !survey.nil? - individual_payment(sale_data, survey, printer_settings.precision, delimiter) + if !sale_data.equal_persons.nil? + individual_payment(sale_data, printer_settings.precision, delimiter) end #end for individual payment @@ -111,9 +112,12 @@ class ReceiptBillA5Pdf < Prawn::Document bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do text "Receipt No: #{sale_data.receipt_no}", :size => self.item_font_size,:align => :left end - bounding_box([self.item_description_width, y_position], :width => self.item_description_width, :height => self.item_height) do - text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right + if sale_data.bookings[0].dining_facility_id.to_i > 0 + bounding_box([self.item_description_width, y_position], :width => self.item_description_width, :height => self.item_height) do + text "#{ sale_data.bookings[0].dining_facility.type } - #{ sale_data.bookings[0].dining_facility.name }" , :size => self.item_font_size,:align => :right + end end + move_down line_move y_position = cursor @@ -126,8 +130,13 @@ class ReceiptBillA5Pdf < Prawn::Document move_down line_move y_position = cursor + if sale_data.bookings[0].dining_facility_id.to_i > 0 + time =sale_data.receipt_date.strftime('%d-%m-%Y') +"("+ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') +"-"+ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p')+")" + else + time = time = sale_data.receipt_date.strftime('%d-%m-%Y %H:%M %p') + end bounding_box([0,y_position], :width =>self.page_width - 20, :height => self.item_height) do - text "Date : #{ sale_data.receipt_date.strftime('%d-%m-%Y') } ( #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } - #{ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p') } )",:size => self.item_font_size,:align => :left + text "Date : #{ time }",:size => self.item_font_size,:align => :left end @@ -481,17 +490,17 @@ class ReceiptBillA5Pdf < Prawn::Document move_down line_move y_position = cursor bounding_box([0,y_position], :width =>self.label_width+50) do - text "Individual amount for #{survey.total_customer} persons", :size => self.item_font_size+1,:align => :left + text "Split Bill for #{sale_data.equal_persons} persons", :size => self.item_font_size+1,:align => :left end bounding_box([0,y_position], :width =>self.label_width) do - move_down line_move - text "Total", :size => self.item_font_size,:align => :left + move_down 15 + text "Amount Due (per person)", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do - move_down line_move - text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)} per person", :size => self.item_font_size,:align => :right + move_down 15 + text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 4c6c51f7..99ae474d 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,5 +1,6 @@ class ReceiptBillPdf < Prawn::Document include ActionView::Helpers::NumberHelper + attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width, :description_width, :price_num_width, :line_move def initialize(printer_settings, sale_items, sale_data, customer_name, item_price_by_accounts, discount_price_by_accounts, member_info = nil,rebate_amount = nil,shop_details, printed_status,current_balance,card_data,survey) self.page_width = printer_settings.page_width @@ -81,8 +82,8 @@ class ReceiptBillPdf < Prawn::Document end #start for individual payment - if !survey.nil? - individual_payment(sale_data, survey, printer_settings.precision, delimiter) + if !sale_data.equal_persons.nil? + individual_payment(sale_data, printer_settings.precision, delimiter) end #end for individual payment @@ -129,9 +130,9 @@ class ReceiptBillPdf < Prawn::Document y_position = cursor if sale_data.bookings[0].dining_facility_id.to_i > 0 - time =sale_data.receipt_date.strftime('%d-%m-%Y') +"("+ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') +"-"+ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p')+")" + time = sale_data.receipt_date.strftime('%d-%m-%Y') +"("+ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') +"-"+ sale_data.bookings[0].checkout_at.utc.getlocal.strftime('%I:%M %p')+")" else - time = time = sale_data.receipt_date.strftime('%d-%m-%Y %H:%M %p') + time = sale_data.receipt_date.strftime('%d-%m-%Y %H:%M %p') end bounding_box([0,y_position], :width =>self.page_width - 10, :height => self.item_height) do @@ -492,17 +493,17 @@ class ReceiptBillPdf < Prawn::Document move_down line_move y_position = cursor bounding_box([0,y_position], :width =>self.label_width+50) do - text "Individual amount for #{survey.total_customer} persons", :size => self.item_font_size+1,:align => :left + text "Split Bill for #{sale_data.equal_persons} persons", :size => self.item_font_size+1,:align => :left end bounding_box([0,y_position], :width =>self.label_width) do move_down 15 - text "Total", :size => self.item_font_size,:align => :left + text "Amount Due (per person)", :size => self.item_font_size,:align => :left end bounding_box([self.label_width,y_position], :width =>self.item_description_width) do move_down 15 - text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)} per person", :size => self.item_font_size,:align => :right + text "#{number_with_precision(per_person, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right end end diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index c3dce804..50673b5f 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -1,6 +1,7 @@
-

<%= t :dashboard %>

+ +

<%= t :date_time %> : <%= Time.zone.now.utc.getlocal.strftime("%Y-%m-%d %I:%M %p") %>

<% if @print_settings.precision.to_i > 0 precision = @print_settings.precision @@ -65,8 +66,28 @@ - <% if current_user.role == 'administrator' || current_user.role == 'manager' %> + +
+
+ + + +
+
+ + + +
+
+
+ +
+
+
+ +
+ <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
@@ -122,10 +143,18 @@
-
+ <% end %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' || current_user.role == 'cashier' %> <% if !@summ_sale.nil? %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' %> +
+ <% else %> +
+
+
+ <% end %>
<%= t :sale %>
@@ -140,11 +169,11 @@ <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.discount") %> : - <%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) %> + <%= number_with_precision( @summ_sale.total_discount, precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> <%= t("views.right_panel.detail.total") %> <%= t("views.right_panel.detail.tax") %> : - <%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter)%> + <%= number_with_precision( @summ_sale.total_tax , precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> <%= t("views.right_panel.detail.total_sale") %> : @@ -165,7 +194,7 @@ <% @sale_data.each do |data| %> <% pay_mth = payment.payment_method %> - <%= data[""+pay_mth+""] %> + <%= number_with_precision(data[""+pay_mth+""], precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> <% end %> @@ -178,7 +207,7 @@ <%= t("views.right_panel.detail.other_payment") %> : - <%= total_card["card"].to_f %> + <%= number_with_precision(total_card["card"], precision: precision.to_i ,delimiter: delimiter) rescue number_with_precision(0, precision: precision.to_i ,delimiter: delimiter) %> <% end %> @@ -188,11 +217,17 @@
+ <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
<% end %> + <% end %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
+ <% else %> +
+ <% end %>
<%= t :customer %>
@@ -231,10 +266,16 @@
+ <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
+ <% end %> + <% if current_user.role == 'administrator' || current_user.role == 'manager' %>
+ <% else %> +
+ <% end %>
<%= t("views.right_panel.detail.order") %>
@@ -278,6 +319,41 @@
+ <% end %>
- <% end %> -
\ No newline at end of file +
+ + \ No newline at end of file diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index ec0a3c68..5f1fe42d 100755 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -18,7 +18,7 @@ <% else %> - + <%end%> Logo SX Restaurant diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index 75428949..e3d08824 100755 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -124,6 +124,9 @@
  • Sale Items
  • +
  • + Product Sale +
  • Receipt
  • diff --git a/app/views/oqs/edit/index.html.erb b/app/views/oqs/edit/index.html.erb index 24599bd1..775b214d 100755 --- a/app/views/oqs/edit/index.html.erb +++ b/app/views/oqs/edit/index.html.erb @@ -118,13 +118,45 @@ $(document).ready(function(){ data: params, success: function(result){ // alert("Updated!"); - window.location.href = '/oqs'; + <% if !@link_type.nil? %> + <% if @link_type == 'oqs' %> + window.location.href = '/oqs'; + <% else %> + <% if !@dining_type.nil? %> + <% if @dining_type == 'Table' %> + window.location.href = '/origami/table/'+<%=@link_type%>; + <% else %> + window.location.href = '/origami/room/'+<%=@link_type%>; + <% end %> + <% else %> + window.location.href = '/origami/table/'+<%=@link_type%>; + <% end %> + <% end %> + <% else %> + window.location.href = '/oqs'; + <% end %> } }); }); $('#back').on('click', function () { + <% if !@link_type.nil? %> + <% if @link_type == 'oqs' %> + window.location.href = '/oqs'; + <% else %> + <% if !@dining_type.nil? %> + <% if @dining_type == 'Table' %> + window.location.href = '/origami/table/'+<%=@link_type%>; + <% else %> + window.location.href = '/origami/room/'+<%=@link_type%>; + <% end %> + <% else %> + window.location.href = '/origami/table/'+<%=@link_type%>; + <% end %> + <% end %> + <% else %> window.location.href = '/oqs'; + <% end %> }) // number key pad diff --git a/app/views/oqs/home/index.html.erb b/app/views/oqs/home/index.html.erb index 1f25e275..33ee74b7 100755 --- a/app/views/oqs/home/index.html.erb +++ b/app/views/oqs/home/index.html.erb @@ -72,7 +72,12 @@
    - <%= qid.type %>-<%= qid.zone %> + <%if qid.type.present?%> + <%= qid.type %>-<%= qid.zone %> + <%else%> + + <%end%> + <%= qid.order_id %>
    @@ -83,13 +88,13 @@ <%= qid.qty %> ] - <% if !qid.set_menu_items.nil? - qid.set_menu_items.each do |item_instance|%> -
    + <% if !qid.set_menu_items.nil? %> + <% qid.set_menu_items.each do |item_instance|%> +
    <%= item_instance %> - - <% end - end %> +
    + <% end %> + <% end %>


    <%= qid.options == "[]"? "" : qid.options %>

    diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 67d90ffd..9190ccf7 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -1,4 +1,3 @@ - <%= stylesheet_link_tag 'addorder', media: 'all', 'data-turbolinks-track': 'reload' %> <%= javascript_include_tag 'addorder', 'data-turbolinks-track': 'reload' %> diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index fb066f7c..cb213a38 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -2,6 +2,21 @@ + <% if !@print_settings.nil? %> + <% if @print_settings.precision.to_i > 0 + precision = @print_settings.precision + else + precision = 0 + end + #check delimiter + if @print_settings.delimiter + delimiter = "," + else + delimiter = "" + end + %> + <% end %> +
    @@ -56,9 +71,9 @@ <% sub_total += sale_item.price%> <%= count %> - <%=sale_item.product_name%>@<%=sale_item.unit_price%> + <%=sale_item.product_name%>@<%=number_with_precision( sale_item.unit_price, precision: precision.to_i )%> <%=sale_item.qty%> - <%=(sale_item.price)%> + <%=(number_with_precision(sale_item.price, precision: precision.to_i ))%> <%end %> @@ -71,7 +86,7 @@ Sub Total - <%=sub_total%> + <%=number_with_precision(sub_total, precision: precision.to_i)%> <%if @sale_data.discount_type == 'member_discount'%> @@ -79,7 +94,7 @@ <%else%> (Discount) <%end%> - (<%=@sale_data.total_discount rescue 0%>) + (<%= number_with_precision(@sale_data.total_discount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>) Tax @@ -91,22 +106,36 @@ <%end%> <%end %>) - <%=@sale_data.total_tax rescue 0%> + <%= number_with_precision(@sale_data.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> Rounding Adj: - <%= @sale_data.rounding_adjustment rescue 0%> + <%= number_with_precision(@sale_data.rounding_adjustment, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> Grand Total - <%=@sale_data.grand_total rescue 0%> + <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%> <%if @balance > 0%> <%= @accountable_type %> - <%=@balance%> + <%=number_with_precision(@balance, precision: precision.to_i )%> <% end %> + <% if !@individual_total[0].nil? %> + + + Split Bill for <%= @individual_total[0]['total_customer'] %> persons + + + + + + Amount Due (per person) + + <%= number_with_precision(@individual_total[0]['per_person_amount'], precision: precision.to_i )%> + + <% end %>
    @@ -124,24 +153,24 @@
    Amount Due
    - - <%= @sale_data.grand_total rescue 0%> + + <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    Cash
    -
    <%= @cash %>
    +
    <%= number_with_precision(@cash, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    Credit
    -
    <%= @credit %>
    +
    <%= number_with_precision(@credit, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    <% if @other == 0.0 && @ppamount == 0.0 && @visacount == 0.0 && @jcbcount == 0.0 && @mastercount == 0.0%>
    Other Payments
    -
    <%= @other %>
    +
    <%= number_with_precision(@other, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i) %>
    <% else %>
    @@ -156,13 +185,13 @@
    MPU
    -
    <%= @other %>
    +
    <%= number_with_precision(@other, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    <% else %> <% end %> @@ -170,13 +199,13 @@
    Redeem
    -
    <%= @ppamount %>
    +
    <%= number_with_precision(@ppamount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    <% else %> <% end %> @@ -184,13 +213,13 @@
    VISA
    -
    <%= @visacount %>
    +
    <%= number_with_precision(@visacount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    <% else %> <% end %> @@ -198,13 +227,13 @@
    JCB
    -
    <%= @jcbcount %>
    +
    <%= number_with_precision(@jcbcount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    <% else %> <% end %> @@ -212,13 +241,13 @@
    MASTER
    -
    <%= @mastercount %>
    +
    <%= number_with_precision(@mastercount, precision: precision.to_i) rescue number_with_precision(0, precision: precision.to_i ) %>
    <% else %> <% end %> @@ -227,18 +256,18 @@
    UNIONPAY
    -
    <%= @unionpaycount %>
    +
    <%= number_with_precision(@unionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    <% else %> <% end %>
    Balance
    -
    <%= @sale_data.grand_total rescue 0 %>
    +
    <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    @@ -295,8 +324,8 @@ reply Back - - +
    diff --git a/app/views/origami/pending_order/show.html.erb b/app/views/origami/pending_order/show.html.erb index c7233400..d94a81d5 100644 --- a/app/views/origami/pending_order/show.html.erb +++ b/app/views/origami/pending_order/show.html.erb @@ -10,12 +10,19 @@
    <% @sales.each do |sale| %> -
    -
    - <%= sale.receipt_no %><%= sale.sale_status %> -
    -
    - <% end %> +
    +
    + <%= sale.receipt_no %>Billed +
    +
    + <% end %> + <% @orders.each do |order| %> +
    +
    + <%= order.booking_id %>new +
    +
    + <% end %>
    @@ -31,19 +38,38 @@
    -
    -   Receipt No: - <%= @sale.receipt_no rescue '' %> - -
    -
    - Date: <%= @sale.created_at.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>   -
    + + <% if @status == 'sale' %> +
    +   Receipt No: + <%= @sale.receipt_no rescue '' %> +
    + <% else%> + +
    +   Order No: + <%= @bookings.booking_orders[0].order_id rescue '' %> +
    + <% end%> + + + <% if @status == 'sale' %> +
    + Date: <%= @sale.created_at.strftime("%d/%m/%Y - %I:%M %p") rescue '-'%>   +
    + <% else%> +
    + Date: <%= @order.created_at.strftime("%I:%M %p") rescue '-'%>   +
    + <% end%>
    -   Customer : <%= @sale.customer.name rescue "-" %> - + <% if @status == 'sale' %> +   Customer : <%= @sale.customer.name rescue "-" %> + <% else%> +   Customer : <%= @order.customer.name rescue "-" %> + <% end%>
    @@ -58,55 +84,64 @@ - <% - sub_total = 0 + <% if @status == 'sale' %> + <% sub_total = 0 @sale.sale_items.each do |sale_item| - sub_total = sub_total + sale_item.price - %> - - <% #unless sale_item.price <= 0 %> - - <%= sale_item.product_name %> - <%= sale_item.qty %> - <%= sale_item.price %> - - <% - - #end - end - - %> + sub_total = sub_total + sale_item.price %> + + + <%= sale_item.product_name %> + <%= sale_item.qty %> + <%= sale_item.price %> + + <% end%> + <% else%> + <% sub_total = 0 + @order_items.each do |order_item| + sub_total = sub_total + order_item.price %> + + + <%= order_item.item_name %> + <%= order_item.qty %> + <%= order_item.price %> + + <% end%> + <% end%> +
    @@ -115,8 +150,15 @@
    + <% if current_user.role != "waiter" || @status != "sale"%> - + <%end%> + <% if current_user.role != "waiter" && @status != "order"%> + + <%end%> + <% if @status != "sale"%> + + <%end%>
    @@ -135,7 +177,7 @@ $(document).ready(function(){ }); $('#addorder').on('click', function () { var table_id = "<%=@table_id%>"; - var booking_id = "<%=@booking%>"; + var booking_id = "<%=@bookings.booking_id%>"; if (table_id) { window.location.href = '/origami/quick_service/modify_order/' + table_id+"/"+$('#sale_id').val(); }else{ @@ -143,5 +185,23 @@ $(document).ready(function(){ } }); + // Bill Request + $('#request_bills').click(function () { + var order_id = $('#save_order_id').val(); + var ajax_url = "/origami/" + order_id + "/request_bills"; + $.ajax({ + type: "GET", + url: ajax_url, + // data: 'order_id='+ order_id, + success: function (result) { + if (!result.status) { + swal("Information!", result.error_message); + } + else { + location.reload(); + } + } + }); + }); }); diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index 74c81b77..4cd6a846 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -277,19 +277,19 @@ sub_total = sub_total + (order_item.price * order_item.qty) # unless order_item.price == 0 %> - - <%= count %> - - <%= order_item.item_name %> - <% if !order_item.set_menu_items.nil? - order_item.set_menu_items.each do |item_instance| %> -
    <%= item_instance %> - <% end - end %> - - <%= order_item.qty %> - <%= order_item.qty*order_item.price %> - + + <%= count %> + + <%= order_item.item_name %> + <% if !order_item.set_menu_items.nil? + order_item.set_menu_items.each do |item_instance| %> +
    <%= item_instance %> + <% end + end %> + + <%= order_item.qty %> + <%= order_item.qty*order_item.price %> + <% # end @@ -345,20 +345,19 @@ @order_items.each do |order_item | count += 1 %> - - - <%= count %> - - <%= order_item.item_name %> - <% if !order_item.set_menu_items.nil? - order_item.set_menu_items.each do |item_instance| %> -
    <%= item_instance %> - <% end - end %> - - <%= order_item.qty %> - <%= order_item.qty*order_item.price %> - + + <%= count %> + + <%= order_item.item_name %> + <% if !order_item.set_menu_items.nil? + order_item.set_menu_items.each do |item_instance| %> +
    <%= item_instance %> + <% end + end %> + + <%= order_item.qty %> + <%= order_item.qty*order_item.price %> + <% end @@ -397,7 +396,10 @@ + <% if current_login_employee.role == "administrator" || current_login_employee.role == "manager" || current_login_employee.role == "supervisor" || current_login_employee.role == "cashier" || current_login_employee.role == "waiter" %> + <% end %> + <% if current_login_employee.role != "waiter" %> <% if @room.bookings.length >= 1 %> <% if @status_order == 'order' && @status_sale != 'sale' %> @@ -420,6 +422,7 @@ <% if @status_sale == 'sale' %> + <% if current_login_employee.role != "waiter" %> + <% end %> + <% end %> + <% if current_login_employee.role != "waiter" %> <% if ENV["SERVER_MODE"] == "cloud" %> @@ -437,14 +447,11 @@ <%end%> <%end%> - <% if !@split_bill.nil? %> - <% if @split_bill == '1' %> - - <% end %> - <% end %> + <% end %> <% end %> + <% if current_login_employee.role != "waiter" %> "> @@ -475,9 +482,10 @@
    - + <% end %> <% end %> + <% end %>
    @@ -901,4 +909,13 @@ $('#add_invoice').on('click',function(){ } }); }); + + /*edit order in oqs*/ + $('.edit_order').on('click',function(){ + var assigned_order_item_id = $(this).attr('data-id'); + var dining_id = "<%= @room.id %>"; + if((assigned_order_item_id!=undefined) && (assigned_order_item_id!='')){ + window.location.href = '/oqs/'+ assigned_order_item_id + "/edit/"+dining_id; + } + }); diff --git a/app/views/origami/sale_edit/edit.html.erb b/app/views/origami/sale_edit/edit.html.erb index 8c1144e5..745286d3 100755 --- a/app/views/origami/sale_edit/edit.html.erb +++ b/app/views/origami/sale_edit/edit.html.erb @@ -1,7 +1,7 @@
    -
    +
    INVOICE DETAILS
    @@ -57,23 +57,26 @@ <%= sale_item.product_name %> - <% if sale_item.remark != 'void' && sale_item.remark != 'edit' && sale_item.remark != 'foc' %> + <% if sale_item.status != 'void' && sale_item.status != 'edit' && sale_item.status != 'foc' %> - + + - + + - - + + + - <% elsif sale_item.qty.to_i < 0 || sale_item.remark == 'edit' %> + <% elsif sale_item.qty.to_i < 0 || sale_item.status == 'edit' %> @@ -148,48 +151,114 @@
    --> - -
    - - - - + +
    + + + + +
    + + + diff --git a/app/views/origami/split_bill/index.html.erb b/app/views/origami/split_bill/index.html.erb index f246e98c..1db44d41 100755 --- a/app/views/origami/split_bill/index.html.erb +++ b/app/views/origami/split_bill/index.html.erb @@ -65,6 +65,8 @@ + + <%=odr_item['item_name'] %> <% if !odr_item['set_menu_items'].nil? @@ -132,6 +134,8 @@ + + <%=order_item[order.order_id.to_s]['item_name'] %> <% if !order_item[order.order_id.to_s]['set_menu_items'].nil? @@ -194,7 +198,9 @@ # Receipt No. Total + <% if !@current_user.nil? && @current_user.role != 'waiter' %> Action + <% end %> <% @sale_data.each_with_index do |sale_data, sale_index| %> @@ -207,9 +213,12 @@ > <%= sale_data.receipt_no %> <%= sale_data.grand_total %> + + <% if !@current_user.nil? && @current_user.role != 'waiter' %> + <% end %> <% end %> <% end %> @@ -228,9 +237,15 @@
    - - - + <% if !@current_user.nil? && @current_user.role != 'waiter' %> + <% if !@sale_data.empty? %> + + <% end %> + <% end %> + <% if !@orders.empty? %> + + + <% end %>
    @@ -249,7 +264,7 @@