diff --git a/.gitignore b/.gitignore index b404db53..e32934b1 100755 --- a/.gitignore +++ b/.gitignore @@ -26,7 +26,7 @@ capybara-*.html /public/assets/* /public/uploads/* /public/swf/* -/public/receipts +/public/receipts/ /coverage/ /spec/tmp/* *.orig diff --git a/Gemfile b/Gemfile index 1d390266..cd92e40b 100755 --- a/Gemfile +++ b/Gemfile @@ -47,9 +47,11 @@ gem 'jquery-fileupload-rails' gem 'cups' gem 'prawn' gem 'prawn-table' -gem 'spreadsheet' gem 'to_xls-rails' - +gem 'rubyzip', '= 1.0.0' +gem 'axlsx', '= 2.0.1' +gem 'axlsx_rails' +gem 'roo' #Reporting gem #gem 'compendium' #gem "cancan" @@ -82,7 +84,6 @@ gem 'kaminari', '~> 1.0.1' gem 'filterrific' gem 'cancancan', '~> 1.10' - #pageless no need for current # gem 'will_paginate' # gem 'pageless-rails', github: 'rorlab/pageless-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 2b156b66..eee001d1 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -50,6 +50,13 @@ GEM airbrussh (1.3.0) sshkit (>= 1.6.1, != 1.7.0) arel (8.0.0) + axlsx (2.0.1) + htmlentities (~> 4.3.1) + nokogiri (>= 1.4.1) + rubyzip (~> 1.0.0) + axlsx_rails (0.5.1) + actionpack (>= 3.1) + axlsx (>= 2.0.1) bcrypt (3.1.11) bindex (0.5.0) builder (3.2.3) @@ -100,6 +107,7 @@ GEM railties (>= 3.2, < 5.2) globalid (0.4.1) activesupport (>= 4.2.0) + htmlentities (4.3.4) httparty (0.15.6) multi_xml (>= 0.5.2) i18n (0.9.1) @@ -201,6 +209,10 @@ GEM rb-inotify (0.9.10) ffi (>= 0.5.0, < 2) redis (3.3.5) + roo (1.13.2) + nokogiri + rubyzip + spreadsheet (> 0.6.4) rspec-core (3.7.0) rspec-support (~> 3.7.0) rspec-expectations (3.7.0) @@ -219,6 +231,7 @@ GEM rspec-support (~> 3.7.0) rspec-support (3.7.0) ruby-ole (1.2.12.1) + rubyzip (1.0.0) sass (3.5.3) sass-listen (~> 4.0.0) sass-listen (4.0.0) @@ -290,6 +303,8 @@ PLATFORMS DEPENDENCIES aescrypt + axlsx (= 2.0.1) + axlsx_rails bcrypt (~> 3.1.7) byebug cancancan (~> 1.10) @@ -325,13 +340,14 @@ DEPENDENCIES rack-cors rails (~> 5.1.0) redis (~> 3.0) + roo rspec-rails (~> 3.5) + rubyzip (= 1.0.0) sass-rails (~> 5.0) schema_to_scaffold shoulda-matchers (~> 3.1) sidekiq simple_form - spreadsheet spring spring-watcher-listen (~> 2.0.0) tether-rails diff --git a/README.md b/README.md index 0cfa2458..e19f7a51 100755 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ ruby 2.4.1p111 * Membership Details Osaka => Auth Token => wu8YvlLmah0CL => New => v3 - => rj0MJ0XI5GsKZehE => Old => v + => rj0MJ0XI5GsKZehE => Old => v2 => code2lab => Old Merchant account => RxzaYyAGzm7VqAZ4hKnv @@ -25,6 +25,7 @@ BITP Campaign Id => {"campaign_type_id": 1} java -jar ~/Documents/Jade.jar http://192.168.1.88:3002 +java -jar ~/Documents/c2l_jade.jar http://192.168.1.151:3002 Person and Extra Time category_code = SPL... //for menu categories special @@ -103,6 +104,9 @@ For Sidekiq 1) If you want to use sidekiq => Create New Lookups => lookup_type = sidekiq, Name = sidekiq , Value = 1 or 0 +For Clear Menu + 1) rake clear:menu # menu,menu item,menu category,menu item instance,account,item option,item attribute,item set + For Check CUp status ###please open sudo cat /etc/sudoers @@ -132,12 +136,29 @@ ADD COLUMN image_path VARCHAR(255); ALTER TABLE sales ADD COLUMN equal_persons INT(11) after rebate_status; + +ALTER TABLE sale_items +ADD COLUMN remark VARCHAR(255) after status; + +ALTER TABLE shops +ADD COLUMN shop_code VARCHAR(255) after name, +ADD COLUMN client_name VARCHAR(255) after shop_code, +ADD COLUMN client_code VARCHAR(255) after client_name; + +ALTER TABLE print_settings +ADD COLUMN brand_name VARCHAR(255) after api_settings, +ADD COLUMN type VARCHAR(255) after brand_name; + +ALTER TABLE tax_profiles +ADD COLUMN group_type VARCHAR(255) after name; + <---- 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 } +<<<<<<< HEAD <---- Extra Fields Script -----> For MoveTablePdf in lookups *** Both Table and Room Moving *** @@ -149,6 +170,13 @@ For MoveTablePdf in print settings ii) Unique Code: MoveTablePdf iii)Template: ... iv) Font: Zawgyi-One v) Printer: #printer name +======= +/* Tax Profile Group Types in lookups */ +1) settings/lookups => { type:tax_profiles, name: Cashier, value:cashier } +2) settings/lookups => { type:tax_profiles, name: Quick Service, value: quick_service } +3) settings/lookups => { type:tax_profiles, name: Doemal, value: doemal } +/* Tax Profile Group Types in lookups */ +>>>>>>> 1c13b0469758fb968c0dfcc1f0a876ed2c5e395a * ToDo list diff --git a/app/assets/javascripts/addorder.js b/app/assets/javascripts/addorder.js index 401d894a..47c6cd4f 100755 --- a/app/assets/javascripts/addorder.js +++ b/app/assets/javascripts/addorder.js @@ -36,7 +36,7 @@ $(function() { image_path = "/image/logo.png"; } - row = '
' + row = '
' +'
' +'
'+ product[field].name +'
' +"
' + row = '
' +'
' +'
'+ menu_items[field].name +'
' +"
" +"" +add+ '' +'
' +'
' - +"
" +''+rowCount+'' - +'' + item_name+ ' ' + name +'-' + option +'' + +'' + item_name+ ' ' + name +' ' + option +'' +'' + qty + '' +'' + parseFloat(total).toFixed(2) @@ -404,22 +406,23 @@ $(function() { +''; $(".summary-items tbody").append(row); var rowCount = $('.summary-items tbody tr').length+1; + var set_option = '' $(items).each(function(i){ code = $(items[i]).attr('data-code'); name = $(items[i]).attr('data-name'); price = $(items[i]).attr('data-price'); - option = $(items[i]).attr('data-options'); + set_option = ($(items[i]).attr('data-options') === 'undefined') ? ' ' :$(items[i]).attr('data-options'); + sub_item = $(items[i]).attr('data-sub-item'); - option = $(items[i]).attr('data-options'); total = qty * price ; row ="" + +set_option+"' data-row ='"+rowCount+ "' data-sub-item ='"+sub_item+ "'>" +''+rowCount+'' - +'' + item_name+ ' ' + name +'-' + option +'' + +'' + item_name+ ' ' + name +' ' + set_option +'' +'' + qty + '' +'' + parseFloat(total).toFixed(2) @@ -659,7 +662,6 @@ $(function() { attribute_arr = get_selected_attributes('selected-attribute'); option_arr = get_selected_attributes('selected-option'); - if (item_row.length>0) { var instances = jQuery.parseJSON(item_row.attr('data-instances')); @@ -698,9 +700,9 @@ $(function() { $('.add_to_order').attr('data-attributes',JSON.stringify(attribute_arr)); $('.add_to_order').attr('data-options',JSON.stringify(option_arr)); var item_data = $(this); - item = get_item(item_data); + item = get_item(item_data,"add_to_order"); customer_display_view(item,"add"); - show_item_detail(item_data); + show_item_detail(item_data,"add_to_order"); calculate_sub_total(); }); //End add order Click @@ -708,13 +710,13 @@ $(function() { // click plus icon for add $(document).on('click', '.add_icon', function(event){ var item_data = $(this); - item = get_item(item_data); + item = get_item(item_data,"add_icon"); customer_display_view(item,"add"); - show_item_detail(item_data); + show_item_detail(item_data,"add_icon"); calculate_sub_total(); }); //End Add Icon Click - function show_item_detail(data){ + function show_item_detail(data,click_type){ qty = parseInt(data.attr('data-qty')); append = 0; @@ -726,23 +728,24 @@ $(function() { }else{ instance = "("+data.attr('data-instance')+")"; } - - d_option = data.attr('data-options'); - if (d_option){ - option_name = "-"+data.attr('data-options'); + d_option = data.attr('data-opt'); + if (click_type != "add_icon"){ + option_name = "-"+data.attr('data-options'); + data_option = data.attr('data-options') ; }else{ - option_name = ''; + option_name = ' '; + data_option = '[]'; } + var rowCount = $('.summary-items tbody tr').length+1; var item_row = $('.summary-items tbody tr'); $(item_row).each(function(i){ item_code = $(item_row[i]).attr('data-code'); instance_code = $(item_row[i]).attr('data-instance-code'); - r_option = $(item_row[i]).attr('data-options'); - - if (item_code == data.attr('data-item-code') && instance_code == data.attr('data-instance-code')&&r_option==d_option) { + r_option = $(item_row[i]).attr('data-opt'); + if (item_code == data.attr('data-item-code') && instance_code == data.attr('data-instance-code')&&r_option == d_option) { if (qty > 1) { qty = parseInt($(item_row[i]).children('#item_qty').text()) + qty; }else{ @@ -766,9 +769,10 @@ $(function() { +instance+ "' data-code='"+data.attr('data-item-code')+"' data-instance-code='" +data.attr('data-instance-code')+"' data-attributes='" +data.attr('data-attributes')+"' data-options ='" + +data_option+"' data-opt ='" +data.attr('data-options')+"' data-row ='"+rowCount+ "'>" +''+rowCount+'' - +'' + data.attr('data-name')+ ' ' + instance +' ' + option_name +'' + +'' + data.attr('data-name')+ ' ' + instance +''+option_name+'' +'' + qty + '' +'' + parseFloat(price).toFixed(2) @@ -822,8 +826,6 @@ $(function() { data: params, dataType: "json", success:function(result){ - console.log(type) - console.log(table_type) if (type == "quick_service") { window.location.href = "/origami/quick_service" }else{ @@ -889,7 +891,7 @@ $(function() { dataType: "json", success:function(result){ if (result.status) { - console.log(result) + if (result.data == null){ swal({ title: "Please Open Shift !", @@ -1178,7 +1180,7 @@ $(function() { for(var i in data) { - row = '' ; $(sub_category).append(row); @@ -1191,7 +1193,7 @@ $(function() { } /* Get Item rows */ - function get_item(data){ + function get_item(data,click_type){ var sale_items = []; var sale_item = {}; @@ -1202,6 +1204,8 @@ $(function() { sale_item.instance_code = data.attr('data-instance-code') sale_item.attributes = data.attr('data-attributes') sale_item.options = data.attr('data-options') + sale_item.opt = data.attr('data-opt') + sale_item.click_type = click_type sale_item.instance = data.attr('data-instance') sale_items.push(sale_item); diff --git a/app/assets/javascripts/channels/second_display_view.js b/app/assets/javascripts/channels/second_display_view.js index c6ac124c..1a1cba86 100644 --- a/app/assets/javascripts/channels/second_display_view.js +++ b/app/assets/javascripts/channels/second_display_view.js @@ -30,11 +30,20 @@ App.checkin = App.cable.subscriptions.create('SecondDisplayViewChannel', { instance = "("+items[i].instance+")"; } - d_option = items[i].options; - if (d_option){ - option_name = "-"+items[i].options; + // d_option = items[i].options; + // if (d_option){ + // option_name = "-"+items[i].options; + // }else{ + // option_name = ''; + // } + + d_option = items[i].opt; + if (items[i].click_type != "add_icon"){ + option_name = "-"+items[i].options; + data_option = items[i].options ; }else{ - option_name = ''; + option_name = ' '; + data_option = '[]'; } var rowCount = $('.second_display_items tbody tr').length+1; @@ -68,7 +77,8 @@ App.checkin = App.cable.subscriptions.create('SecondDisplayViewChannel', { +instance+ "' data-code='"+items[i].item_code+"' data-instance-code='" +items[i].instance_code+"' data-attributes='" +items[i].attributes+"' data-options ='" - +items[i].options+"' data-row ='"+rowCount+ "'>" + +data_option+"' data-opt ='" + +items[i].options+"' data-row ='"+rowCount+ "'>" +''+rowCount+'' +'' + items[i].name+ ' ' + instance + ' ' + option_name +'' +'' + qty + '' diff --git a/app/assets/javascripts/custom.js b/app/assets/javascripts/custom.js index a2011022..778de553 100644 --- a/app/assets/javascripts/custom.js +++ b/app/assets/javascripts/custom.js @@ -9,7 +9,8 @@ $(document).ready(function() { color: 'rgba(0,0,0,0.5)', alwaysVisible: false, borderRadius: '0', - railBorderRadius: '0' + railBorderRadius: '0', + touchScrollStep : 25 }); $('#order-detail-slimscroll').slimScroll({ @@ -18,7 +19,18 @@ $(document).ready(function() { color: 'rgba(0,0,0,0.5)', alwaysVisible: false, borderRadius: '0', - railBorderRadius: '0' + railBorderRadius: '0', + touchScrollStep : 25 + }); + + $('#menu-slimscroll').slimScroll({ + height: height-$('#menu-slimscroll').attr('data-height'), + size: '5px', + color: 'rgba(0,0,0,0.5)', + alwaysVisible: false, + borderRadius: '0', + railBorderRadius: '0', + touchScrollStep : 25 }); // $('.delete').click(function(){ diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 7f3febba..f4bb9488 100755 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -270,7 +270,7 @@ function setCommPorts(comPortLists) { closeOnCancel: false, allowOutsideClick: false }, function () { - window.location.href = '/origami/sale/'+ sale_id + "/payment/others_payment"; + window.location.href = '/origami/sale/'+ sale_id +"/"+cashier_type+"/payment/others_payment"; }); } } @@ -363,6 +363,8 @@ function resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amoun }else{ if(payment_type!="master"){ payment_type = payment_type.toUpperCase(); + }else{ + payment_type = "Master"; } swal({ title: 'Oops', @@ -381,4 +383,4 @@ function resCBPay(resMsg,card_sale_trans_id,cmd_type,payment_type,bnk_bill_amoun function setHeaderBreadCrumb(params){ $("#others_payment").html(params); -} \ No newline at end of file +} diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 07c7428f..f882e526 100755 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -198,6 +198,18 @@ select.form-control { background-color: blue !important; } +.selected-payment { + color: #fff !important; + background-color: blue !important; +} +.payment_btn { + white-space: normal !important; + margin-bottom: 15px; + margin-right: 15px; + color:#fff !important; + # background-color: green !important; +} + /* Reciept Style */ #order-charges-table td { border-top: none !important; @@ -399,7 +411,7 @@ i.logout_icon{ /* Start Is Member Modal */ #is_memberModal .modal-body { - height: 200px !important; + height: 260px !important; } #is_memberModal .btn { diff --git a/app/controllers/api/orders_controller.rb b/app/controllers/api/orders_controller.rb index 2e9602c8..383a6606 100755 --- a/app/controllers/api/orders_controller.rb +++ b/app/controllers/api/orders_controller.rb @@ -67,7 +67,8 @@ class Api::OrdersController < Api::ApiController end } #end extra time - + puts params[:order_items] + puts "ORDER ITEMS" # begin @order = Order.new @order.source = params[:order_source] @@ -171,9 +172,9 @@ class Api::OrdersController < Api::ApiController # Update customer info, Guest Info # Input Params # order_id , order_items {[item_code, item_instance_code , qty, option, variants]} - def update + # def update - end + # end def order_params params.permits(:order_source, :booking_id,:order_type, @@ -198,4 +199,59 @@ class Api::OrdersController < Api::ApiController end return status end + + def update + Rails.logger.debug "Booking ID - " + params[:booking_id].to_s + if checkin_checkout_time(params[:booking_id]) + Rails.logger.debug "Order Item ID - " + params[:order_item_id].to_s + + order_items_id = params[:order_item_id] + qty_weight = params[:quantity].to_f + remarks = params[:remark] + + order_item = OrderItem.find(order_items_id) + before_updated_qty = order_item.qty + + order_item.item_order_by = current_login_employee.name + order_item.qty = qty_weight + order_item.remark = remarks + order_item.save + + if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # print + assigned_item = AssignedOrderItem.find_by_instance_code(order_item.item_instance_code) + # order queue stations + oqs = assigned_item.order_queue_station + + order_slim_pdf = Lookup.collection_of("print_settings") #print_settings with name:OrderSlimPdf + + unique_code="OrderItemPdf" + if !order_slim_pdf.empty? + order_slim_pdf.each do |order_item_slim| + if order_item_slim[0] == 'OrderSlimPdf' + if order_item_slim[1] == '1' + unique_code="OrderItemSlimPdf" + else + unique_code="OrderItemPdf" + end + elsif order_item_slim[0] == 'OrderSetPdf' + if order_item_slim[1] == '1' + unique_code="OrderSetItemPdf" + else + unique_code="OrderItemPdf" + end + end + end + end + + print_settings=PrintSetting.find_by_unique_code(unique_code) + order_queue_printer= Printer::OrderQueuePrinter.new(print_settings) + order_queue_printer.print_order_item(print_settings, oqs, order_item.order_id, order_items_id, print_status=" (Cancelled)", before_updated_qty ) + end + + return return_json_status_with_code(200, "updated successfully!") + else + return return_json_status_with_code(406, "Checkout time is over!") + end + end end diff --git a/app/controllers/base_crm_controller.rb b/app/controllers/base_crm_controller.rb index 3b9e0176..65350605 100755 --- a/app/controllers/base_crm_controller.rb +++ b/app/controllers/base_crm_controller.rb @@ -2,6 +2,8 @@ class BaseCrmController < ActionController::Base include LoginVerification layout "CRM" + before_action :check_user + #before_action :check_installation protect_from_forgery with: :exception @@ -22,8 +24,10 @@ class BaseCrmController < ActionController::Base { locale: I18n.locale } end - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + def check_user + if current_user.nil? + redirect_to root_path + end end #Shop Name in Navbor diff --git a/app/controllers/base_inventory_controller.rb b/app/controllers/base_inventory_controller.rb index a88a3abb..ebbd32e3 100755 --- a/app/controllers/base_inventory_controller.rb +++ b/app/controllers/base_inventory_controller.rb @@ -2,6 +2,8 @@ class BaseInventoryController < ActionController::Base include LoginVerification layout "inventory" + before_action :check_user + #before_action :check_installation protect_from_forgery with: :exception @@ -12,8 +14,10 @@ class BaseInventoryController < ActionController::Base redirect_to root_path end - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + def check_user + if current_user.nil? + redirect_to root_path + end end #Shop Name in Navbor diff --git a/app/controllers/base_oqs_controller.rb b/app/controllers/base_oqs_controller.rb index 0f093913..2b621cf1 100755 --- a/app/controllers/base_oqs_controller.rb +++ b/app/controllers/base_oqs_controller.rb @@ -2,6 +2,8 @@ class BaseOqsController < ActionController::Base include LoginVerification layout "OQS" + before_action :check_user + #before_action :check_installation protect_from_forgery with: :exception @@ -21,9 +23,11 @@ class BaseOqsController < ActionController::Base def default_url_options { locale: I18n.locale } end - - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + + def check_user + if current_user.nil? + redirect_to root_path + end end #Shop Name in Navbor diff --git a/app/controllers/base_origami_controller.rb b/app/controllers/base_origami_controller.rb index 8c4f3aaa..e14a6959 100755 --- a/app/controllers/base_origami_controller.rb +++ b/app/controllers/base_origami_controller.rb @@ -2,7 +2,7 @@ class BaseOrigamiController < ActionController::Base include LoginVerification layout "origami" - # before_action :checkin_process + before_action :check_user #before_action :check_installation protect_from_forgery with: :exception @@ -14,8 +14,10 @@ class BaseOrigamiController < ActionController::Base redirect_to origami_dashboard_path end - def current_user - @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + def check_user + if current_user.nil? + redirect_to root_path + end end # def checkin_process diff --git a/app/controllers/base_report_controller.rb b/app/controllers/base_report_controller.rb index e96e97c8..51c250f8 100755 --- a/app/controllers/base_report_controller.rb +++ b/app/controllers/base_report_controller.rb @@ -2,6 +2,8 @@ class BaseReportController < ActionController::Base include LoginVerification layout "application" + before_action :check_user + #before_action :check_installation protect_from_forgery with: :exception @@ -83,6 +85,12 @@ class BaseReportController < ActionController::Base return from, to end + def check_user + if current_user.nil? + redirect_to root_path + end + end + #Shop Name in Navbor def shop_detail @shop = Shop.first diff --git a/app/controllers/base_waiter_controller.rb b/app/controllers/base_waiter_controller.rb index 71303213..94d1cd45 100755 --- a/app/controllers/base_waiter_controller.rb +++ b/app/controllers/base_waiter_controller.rb @@ -2,13 +2,21 @@ class BaseWaiterController < ActionController::Base include LoginVerification layout "waiter" + before_action :check_user + #before_action :check_installation protect_from_forgery with: :exception helper_method :shop_detail - #Shop Name in Navbor - def shop_detail - @shop = Shop.first - end + def check_user + if current_user.nil? + redirect_to root_path + end + end + + #Shop Name in Navbor + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/concerns/login_verification.rb b/app/controllers/concerns/login_verification.rb index bb9df067..14b1e2e1 100755 --- a/app/controllers/concerns/login_verification.rb +++ b/app/controllers/concerns/login_verification.rb @@ -33,10 +33,10 @@ module LoginVerification protected # Authenticate the user with token based authentication def authenticate - authenticate_session_token || render_unauthorized + authenticate_session_token || render_unauthorized end - def authenticate_session_token + def authenticate_session_token token = session[:session_token] if (token) #@current_user = User.find_by(api_key: token) @@ -50,7 +50,7 @@ module LoginVerification end end - def render_unauthorized() + def render_unauthorized redirect_to root_path end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 147b2ee4..d2b0ad36 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -2,8 +2,21 @@ class HomeController < ApplicationController # layout "application", except: [:index, :show] # skip_before_action :authenticate, only: [:index, :show, :create, :update, :destroy] + before_action :check_user, only: :dashboard + helper_method :shop_detail + # Special check for only dashboard + def check_user + if current_user.nil? + redirect_to root_path + end + end + + def current_user + @current_user ||= Employee.find_by_token_session(session[:session_token]) if session[:session_token] + end + def index # @employees = Employee.all_emp_except_waiter.order("name asc") @employees = Employee.all.order("name asc") @@ -67,63 +80,78 @@ class HomeController < ApplicationController end def dashboard - @from, @to = get_date_range_from_params + @from, @to, @from_time, @to_time = 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,@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) + if !@from.nil? && !@to.nil? + if !@from_time.nil? && @to_time.nil? + @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() + else + @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + end + else + @orders = Sale::where("payment_status='new' and sale_status='bill' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() + end + if !@from.nil? && !@to.nil? + if !@from_time.nil? && @to_time.nil? + @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}' and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%m') between '#{@from_time}' and '#{@to_time}'").count() + else + @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') between '#{@from}' and '#{@to}'").count() + end + else + @sales = Sale::where("payment_status='paid' and sale_status='completed' and DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'").count() + end + @top_products = Sale.top_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty') + @bottom_products = Sale.bottom_products(today,current_user,@from,@to,@from_time,@to_time).sum('i.qty') + @hourly_sales = Sale.hourly_sales(today,current_user,@from,@to,@from_time,@to_time).sum(:grand_total) # .group_by_hour(:created_at, :time_zone => 'Asia/Rangoon',format: '%I:%p') # .sum(:grand_total) - @employee_sales = Sale.employee_sales(today,@from,@to) + @employee_sales = Sale.employee_sales(today,current_user,@from,@to,@from_time,@to_time) .sum('(CASE WHEN sp.payment_method="cash" THEN (sp.payment_amount - sales.amount_changed) ELSE sp.payment_amount END)') - @inventories = StockJournal.inventory_balances(today,@from,@to).sum(:balance) + @inventories = StockJournal.inventory_balances(today,@from,@to,@from_time,@to_time).sum(:balance) - @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) + @total_sale = Sale.total_sale(today,current_user,@from,@to,@from_time,@to_time) + @total_count = Sale.total_count(today,current_user,@from,@to,@from_time,@to_time) + @total_card = Sale.total_card_sale(today,current_user,@from,@to,@from_time,@to_time) + @total_credit = Sale.credit_payment(today,current_user,@from,@to,@from_time,@to_time) @sale_data = Array.new - @total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to) + @total_payment_methods = Sale.total_payment_methods(today,current_user,@from,@to,@from_time,@to_time) if !@total_payment_methods.nil? @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, current_user,@from,@to) + if payment.payment_method == "mpu" || payment.payment_method == "visa" || payment.payment_method == "master" || payment.payment_method == "jcb" || payment.payment_method == "unionpay" + pay = Sale.payment_sale('card', today, current_user,@from,@to,@from_time,@to_time) @sale_data.push({'card' => pay.payment_amount}) else - pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to) + pay = Sale.payment_sale(payment.payment_method, today, current_user,@from,@to,@from_time,@to_time) @sale_data.push({payment.payment_method => pay.payment_amount}) end end end - @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) + @summ_sale = Sale.summary_sale_receipt(today,current_user,@from,@to,@from_time,@to_time) + @total_customer = Sale.total_customer(today,current_user,@from,@to,@from_time,@to_time) + @total_dinein = Sale.total_dinein(today,current_user,@from,@to,@from_time,@to_time) + @total_takeaway = Sale.total_takeaway(today,current_user,@from,@to,@from_time,@to_time) + @total_other_customer = Sale.total_other_customer(today,current_user,@from,@to,@from_time,@to_time) + @total_membership = Sale.total_membership(today,current_user,@from,@to,@from_time,@to_time) - @total_order = Sale.total_order(today,current_user,@from,@to) - @total_accounts = Sale.total_account(today,current_user,@from,@to) + @total_order = Sale.total_order(today,current_user,@from,@to,@from_time,@to_time) + @total_accounts = Sale.total_account(today,current_user,@from,@to,@from_time,@to_time) @account_data = Array.new if !@total_accounts.nil? @total_accounts.each do |account| - acc = Sale.account_data(account.account_id, today,current_user,@from,@to) + acc = Sale.account_data(account.account_id, today,current_user,@from,@to,@from_time,@to_time) if !acc.nil? @account_data.push({account.title => acc.cnt_acc, account.title + '_amount' => acc.total_acc}) end end end - @top_items = Sale.top_items(today,current_user,@from,@to) - @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to) + @top_items = Sale.top_items(today,current_user,@from,@to,@from_time,@to_time) + @total_foc_items = Sale.total_foc_items(today,current_user,@from,@to,@from_time,@to_time) # get printer info @print_settings = PrintSetting.get_precision_delimiter() @@ -177,18 +205,23 @@ class HomeController < ApplicationController def get_date_range_from_params from = params[:from] - to = params[:to] + to = params[:to] + from_time = params[:from_time] + to_time = params[:to_time] 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 + # 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 + + from = DateTime.parse(from).utc.getlocal.strftime('%Y-%m-%d') + to = DateTime.parse(to).utc.getlocal.strftime('%Y-%m-%d') end - return from, to + return from, to, from_time, to_time end #Shop Name in Navbor diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb old mode 100755 new mode 100644 index b123ac73..ccef4e4a --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -3,9 +3,15 @@ class Oqs::EditController < BaseOqsController assigned_item_id = params[:id] @link_type = params[:type] @dining_type = nil + @booking = 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 }'") + elsif params[:type] == "pending" + assigned_item = OrderItem.find(assigned_item_id) + @booking = Booking.joins(" JOIN booking_orders as bko on bko.booking_id = bookings.booking_id") + .where("bko.order_id = '#{assigned_item.order_id}'").first() + @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_instance_code='#{ assigned_item.item_instance_code }'") else assigned_item = OrderItem.find(assigned_item_id) dining = DiningFacility.find_by_id(params[:type]) @@ -25,13 +31,6 @@ class Oqs::EditController < BaseOqsController order_item.item_order_by = current_user.name order_item.qty = qty_weight order_item.remark = remarks - if !order_item.set_menu_items.nil? - instance_item_sets = JSON.parse(order_item.set_menu_items) - instance_item_sets.each_with_index do |instance_item, instance_index| - instance_item_sets[instance_index]["quantity"] = qty_weight - end - order_item.set_menu_items = instance_item_sets.to_json - end order_item.save if ENV["SERVER_MODE"] != "cloud" #no print in cloud server @@ -67,4 +66,9 @@ class Oqs::EditController < BaseOqsController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index 7dd2b3f0..0e905724 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -1,6 +1,6 @@ class Origami::AddordersController < BaseOrigamiController # before_action :set_dining, only: [:detail] - + def index @tables = Table.all.active.order('zone_id asc').group("zone_id") @rooms = Room.all.active.order('zone_id asc').group("zone_id") @@ -94,20 +94,20 @@ class Origami::AddordersController < BaseOrigamiController extra_time = Time.at(time) end end - if i["parent_order_item_id"] - items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": i["options"]} + if i["parent_order_item_id"]; + items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"parent_order_item_id": i["parent_order_item_id"],"options": JSON.parse(i["options"])} else - items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": i["options"]} + items = {"order_item_id": i["order_item_id"],"item_instance_code": i["item_instance_code"],"quantity": i["quantity"],"options": JSON.parse(i["options"])} end items_arr.push(items) } # begin - if params[:order_source] == "quick_service" - customer_id = "CUS-000000000002" # for no customer id from mobile - else + # if params[:order_source] == "quick_service" + # customer_id = "CUS-000000000002" # for no customer id from mobile + # else customer_id = params[:customer_id] == ""? "CUS-000000000001" : params[:customer_id] # for no customer id from mobile - end + # end @order = Order.new @order.source = params[:order_source] @order.order_type = params[:order_type] diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 234a1dc5..c3a3d3b9 100755 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -98,10 +98,10 @@ class Origami::CustomersController < BaseOrigamiController def update_sale_by_customer - id = params[:sale_id][0,3] - customer_id = params[:customer_id] - customer = Customer.find(customer_id) - + id = params[:sale_id][0,3] + customer_id = params[:customer_id] + customer = Customer.find(customer_id) + order_source = params[:type] # Check and find with card no # if(!customer_id.include? "CUS") # customer = Customer.find_by_paypar_account_no(customer_id) @@ -135,7 +135,7 @@ class Origami::CustomersController < BaseOrigamiController if status == true render json: JSON.generate({:status => true}) if(id == "SAL") - sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount) + sale.compute_by_sale_items(sale.sale_id, sale.sale_items, sale.total_discount, nil, order_source) end else render json: JSON.generate({:status => false, :error_message => "Record not found"}) diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 8e390015..6add4a12 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -20,10 +20,12 @@ class Origami::DiscountsController < BaseOrigamiController #discount page show from origami index with selected order def create + order_source = params[:cashier_type] sale_id = params[:sale_id] discount_items = JSON.parse(params[:discount_items]) overall_discount = params[:overall_discount] sub_total = params[:sub_total] + if Sale.exists?(sale_id) sale = Sale.find(sale_id) @@ -82,7 +84,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"OVERALLDISCOUNT" ) end - sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f) + sale.compute_by_sale_items(sale_id, sale.sale_items, overall_discount.to_f, nil,order_source) if !table.nil? result = {:status=> "Success", :table_id => table_id, :table_type => table.type } else @@ -102,6 +104,7 @@ class Origami::DiscountsController < BaseOrigamiController # Remove selected discount Items def remove_discount_items + order_source = params[:cashier_type] sale_id = params[:sale_id] discount_items = JSON.parse(params[:discount_items]) if Sale.exists?(sale_id) @@ -136,7 +139,7 @@ class Origami::DiscountsController < BaseOrigamiController # sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax; # sale.save # Re-calc All Amount in Sale - sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount) + sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount, nil, order_source) if table.nil? result = {:status=> "Success"} else @@ -158,6 +161,7 @@ class Origami::DiscountsController < BaseOrigamiController # Remove all discount Items def remove_all_discount sale_id = params[:id] + order_source = params[:type] if Sale.exists?(sale_id) sale = Sale.find(sale_id) @@ -197,7 +201,7 @@ class Origami::DiscountsController < BaseOrigamiController sale_audit = SaleAudit.record_audit_discount(sale.sale_id,sale.cashier_id, action_by,remark,"REMOVEALLDISCOUNT" ) # Re-calc All Amount in Sale - sale.compute_by_sale_items(sale_id, sale.sale_items, 0) + sale.compute_by_sale_items(sale_id, sale.sale_items, 0, nil, order_source) if table.nil? result = {:status=> "Success"} else @@ -218,7 +222,7 @@ class Origami::DiscountsController < BaseOrigamiController # Member Discount def member_discount - + order_source = params[:cashier_type] sale_id = params[:sale_id] is_card = params[:is_card] sub_total = params[:sub_total] @@ -297,7 +301,7 @@ class Origami::DiscountsController < BaseOrigamiController if response["discount_bonus_earned"] discount_amount = discount_amount + response["discount_bonus_earned"] end - sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount') + sale.compute_by_sale_items(sale_id, sale.sale_items, discount_amount, 'member_discount', order_source) result = {:status=> "Success",:title=>"Member Discount", :table_id => table_id,:table_type => table_type } elsif response["status"] == "500" result = {:status=> response["error"],:title=>"Alert", :table_id => table_id,:table_type => table_type } diff --git a/app/controllers/origami/jcb_controller.rb b/app/controllers/origami/jcb_controller.rb old mode 100755 new mode 100644 index e17c773e..7d8ea46b --- a/app/controllers/origami/jcb_controller.rb +++ b/app/controllers/origami/jcb_controller.rb @@ -5,32 +5,44 @@ class Origami::JcbController < BaseOrigamiController @cashier_type = params[:type] # limit jcb_amount sale_data = Sale.find_by_sale_id(@sale_id) - total = sale_data.grand_total + total = 0 @jcbcount = 0 - others = 0 + @shop = Shop::ShopDetail + @rounding_adj = 0 + @can_jcb = 0 + @member_discount= 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total + + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "jcb" + @jcbcount = @jcbcount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_jcb = total - @jcbcount - others - @shop = Shop::ShopDetail - if @shop.is_rounding_adj - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - else - new_total = sale_data.grand_total - end - @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| - if sale_payment.payment_method == "jcb" - @jcbcount = @jcbcount + sale_payment.payment_amount - else - others = others + sale_payment.payment_amount - end - end - @can_jcb = total - @jcbcount - others - @member_discount = MembershipSetting.find_by_discount(1) - @sub_total = sale_data.total_amount - @membership_id = sale_data.customer.membership_id - #for bank integration - @receipt_no = sale_data.receipt_no + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no + end + bank_integration = Lookup.collection_of('bank_integration') @bank_integration = 0 if !bank_integration[0].nil? @@ -58,4 +70,9 @@ class Origami::JcbController < BaseOrigamiController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/origami/junction_pay_controller.rb b/app/controllers/origami/junction_pay_controller.rb new file mode 100644 index 00000000..1c52a271 --- /dev/null +++ b/app/controllers/origami/junction_pay_controller.rb @@ -0,0 +1,70 @@ +class Origami::JunctionPayController < BaseOrigamiController + + def index + @sale_id = params[:sale_id] + @cashier_type = params[:type] + # limit jcb_amount + sale_data = Sale.find_by_sale_id(@sale_id) + total = sale_data.grand_total + @junction_pay_count = 0 + others = 0 + @cashier_id = current_user.emp_id + + @payment_method_setting_nav = PaymentMethodSetting.all + @shop = Shop::ShopDetail + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total + + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "JunctionPay" + @junction_pay_count = @junction_pay_count + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_junction_pay = total - @junction_pay_count - others + + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no + end + + def create + gift_amount = params[:gift_amount] + voucher_amount = params[:voucher_amount] + voucher_no = params[:voucher_no] + sale_id = params[:sale_id] + + # Gift card or Voucher classified and add for payment_reference + remarks = '' + cash = (gift_amount.to_f + voucher_amount.to_f) + if gift_amount.to_f > 0 + remarks = "Junciton Gift Card Payment. RefNo-" + voucher_no + else + remarks = "Junciton Voucher Payment. RefNo-" + voucher_no + end + + if(Sale.exists?(sale_id)) + saleObj = Sale.find(sale_id) + shop_details = Shop::ShopDetail + + # rounding adjustment + # if shop_details.is_rounding_adj + # new_total = Sale.get_rounding_adjustment(saleObj.grand_total) + # rounding_adj = new_total-saleObj.grand_total + # saleObj.update_attributes(grand_total: new_total,old_grand_total: saleObj.grand_total,rounding_adjustment:rounding_adj) + # end + + # saleObj = Sale.find(sale_id) + sale_payment = SalePayment.new + @status, @sale = sale_payment.process_payment(saleObj, @user, cash, "JunctionPay", remarks) + end + end + +end diff --git a/app/controllers/origami/master_controller.rb b/app/controllers/origami/master_controller.rb old mode 100755 new mode 100644 index 95710f11..747da493 --- a/app/controllers/origami/master_controller.rb +++ b/app/controllers/origami/master_controller.rb @@ -5,31 +5,41 @@ class Origami::MasterController < BaseOrigamiController @cashier_type = params[:type] # limit master_amount sale_data = Sale.find_by_sale_id(@sale_id) - total = sale_data.grand_total + total = 0 @mastercount = 0 - others = 0 - - @shop = Shop::ShopDetail - if @shop.is_rounding_adj - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - else - new_total = sale_data.grand_total - end - @rounding_adj = new_total-sale_data.grand_total + @shop = Shop::ShopDetail + @rounding_adj = 0 + @can_master = 0 + @member_discount = 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total - sale_data.sale_payments.each do |sale_payment| - if sale_payment.payment_method == "master" - @mastercount = @mastercount + sale_payment.payment_amount - else - others = others + sale_payment.payment_amount - end + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "master" + @mastercount = @mastercount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_master = total - @mastercount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no end - @can_master = total - @mastercount - others - @member_discount = MembershipSetting.find_by_discount(1) - @sub_total = sale_data.total_amount - @membership_id = sale_data.customer.membership_id - #for bank integration - @receipt_no = sale_data.receipt_no bank_integration = Lookup.collection_of('bank_integration') @bank_integration = 0 if !bank_integration[0].nil? @@ -57,4 +67,9 @@ class Origami::MasterController < BaseOrigamiController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/origami/mpu_controller.rb b/app/controllers/origami/mpu_controller.rb old mode 100755 new mode 100644 index f577cb9d..1b125bda --- a/app/controllers/origami/mpu_controller.rb +++ b/app/controllers/origami/mpu_controller.rb @@ -4,32 +4,43 @@ class Origami::MpuController < BaseOrigamiController @cashier_type = params[:type] # limit mpu_amount sale_data = Sale.find_by_sale_id(@sale_id) - total = sale_data.grand_total + total = 0 @mpucount = 0 - others = 0 - @shop = Shop::ShopDetail - if @shop.is_rounding_adj - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - else - new_total = sale_data.grand_total - end - @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| - if sale_payment.payment_method == "mpu" - @mpucount = @mpucount + sale_payment.payment_amount - else - others = others + sale_payment.payment_amount - end - end - @can_mpu = total - @mpucount - others + @rounding_adj = 0 + @can_mpu = 0 + @member_discount = 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total + + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "mpu" + @mpucount = @mpucount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_mpu = total - @mpucount - others + + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no + end - @member_discount = MembershipSetting.find_by_discount(1) - @sub_total = sale_data.total_amount - @membership_id = sale_data.customer.membership_id - #for bank integration - @receipt_no = sale_data.receipt_no bank_integration = Lookup.collection_of('bank_integration') @bank_integration = 0 if !bank_integration[0].nil? @@ -57,4 +68,9 @@ class Origami::MpuController < BaseOrigamiController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index 8bba3800..def94a1f 100755 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -19,6 +19,7 @@ class Origami::OtherChargesController < BaseOrigamiController sale_id = params[:sale_id] other_charges_items = JSON.parse(params[:other_charges_items]) sub_total = params[:sub_total] + cashier_type = params[:cashier_type] if Sale.exists?(sale_id) sale = Sale.find(sale_id) @@ -68,7 +69,7 @@ class Origami::OtherChargesController < BaseOrigamiController end # Re-calc All Amount in Sale - sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount) + sale.compute_by_sale_items(sale_id, sale.sale_items, sale.total_discount, nil, cashier_type) end if !table.nil? dining = {:table_id => table_id, :table_type => table.type } diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index db282a00..c2797047 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -27,7 +27,7 @@ class Origami::PaymentsController < BaseOrigamiController cashier_terminal = CashierTerminal.find(shift.cashier_terminal_id) end - if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf # Print for First Bill to Customer unique_code = "ReceiptBillPdf" @@ -79,8 +79,17 @@ 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) - end + filename, receipt_no, cashier_printer = 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) + + result = { + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + render :json => result.to_json + # end end def create @@ -131,7 +140,7 @@ class Origami::PaymentsController < BaseOrigamiController end # For Print - if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf unique_code = "ReceiptBillPdf" if !receipt_bill_a5_pdf.empty? @@ -170,8 +179,11 @@ class Origami::PaymentsController < BaseOrigamiController end booking.booking_orders.each do |order| - Order.pay_process_order_queue(order.order_id,table_id) + # Order.pay_process_order_queue(order.order_id, table_id) + oqs = OrderQueueStation.new + oqs.pay_process_order_queue(order.order_id, table_id) end + end #for card sale data @@ -197,7 +209,8 @@ class Origami::PaymentsController < BaseOrigamiController filename, sale_receipt_no, printer_name = 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) render json: JSON.generate({:status => saleObj.rebate_status, :message => "Can't Rebate coz of Sever Error ", :filename => filename, :receipt_no => sale_receipt_no, :printer_name => printer_name}) - end + + #end end end @@ -215,15 +228,18 @@ class Origami::PaymentsController < BaseOrigamiController @jcbcount= 0.0 @mastercount = 0.0 @unionpaycount = 0.0 + @junctionpaycount = 0.0 @credit = 0.0 @sale_data = Sale.find_by_sale_id(sale_id) - @balance = 0.00 + @balance = 0 @accountable_type = '' @table_no = '' @dining = '' @shop = Shop::ShopDetail #show shop info + @customer_lists = Customer.where("customer_id = 'CUS-000000000001' or customer_id = 'CUS-000000000002'") + saleObj = Sale.find(sale_id) #total customer with individual total amount @@ -273,10 +289,11 @@ class Origami::PaymentsController < BaseOrigamiController #get customer amount @customer = Customer.find(@sale_data.customer_id) - accounts = @customer.tax_profiles + # accounts = @customer.tax_profiles + accounts = TaxProfile.where("group_type = ?",@cashier_type).order("order_by ASC") @account_arr =[] accounts.each do |acc| - account = TaxProfile.find(acc) + account = TaxProfile.find(acc.id) @account_arr.push(account) end @@ -287,7 +304,7 @@ class Origami::PaymentsController < BaseOrigamiController if response["status"]==true response["account_data"].each do |res| if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" - @balance += res["balance"] + @balance = @balance.to_f + res["balance"].to_f # @accountable_type = res["accountable_type"] @accountable_type = "Rebate Balance" end @@ -327,6 +344,8 @@ class Origami::PaymentsController < BaseOrigamiController @mastercount += spay.payment_amount elsif spay.payment_method == "unionpay" @unionpaycount += spay.payment_amount + elsif spay.payment_method == "JunctionPay" + @junctionpaycount += spay.payment_amount elsif spay.payment_method == "creditnote" @credit += spay.payment_amount end @@ -404,19 +423,19 @@ class Origami::PaymentsController < BaseOrigamiController member_info = nil rebate_amount = nil current_balance = nil + order_source = params[:type] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) if saleObj.discount_type == "member_discount" saleObj.update_attributes(rounding_adjustment: 0) - saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0) + saleObj.compute_by_sale_items(sale_id, saleObj.sale_items,0,order_source) end saleObj.update_attributes(rounding_adjustment: 0) sale_payment = SalePayment.new sale_payment.process_payment(saleObj, current_user.name, cash, "foc" ,remark) - # For Cashier by Zone bookings = Booking.where("sale_id='#{sale_id}'") # if bookings.count > 1 @@ -438,7 +457,7 @@ class Origami::PaymentsController < BaseOrigamiController # Re-call Sale Data saleObj = Sale.find(sale_id) - if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server unique_code = "ReceiptBillPdf" customer= Customer.find(saleObj.customer_id) @@ -452,7 +471,17 @@ 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) + + filename, sale_receipt_no, printer_name = 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) + result = { + :status => true, + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + render :json => result.to_json if params[:type] == "quick_service" booking = Booking.find_by_sale_id(sale_id) @@ -466,7 +495,7 @@ class Origami::PaymentsController < BaseOrigamiController Order.pay_process_order_queue(order.order_id,table_id) end end - end + # end end end @@ -512,6 +541,15 @@ class Origami::PaymentsController < BaseOrigamiController printer = Printer::ReceiptPrinter.new(print_settings) printer.print_receipt_pdf(filename,receipt_no,print_settings.print_copies,printer_name) - render :json => {status: true} + result = { + :status => true, + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + render :json => result.to_json + # render :json => {status: true} end end \ No newline at end of file diff --git a/app/controllers/origami/quick_service_controller.rb b/app/controllers/origami/quick_service_controller.rb index 44dcfcb8..8abcfcc8 100644 --- a/app/controllers/origami/quick_service_controller.rb +++ b/app/controllers/origami/quick_service_controller.rb @@ -1,6 +1,12 @@ class Origami::QuickServiceController < ApplicationController # before_action :set_dining, only: [:detail] - + before_action :check_user + def check_user + if current_user.nil? + redirect_to root_path + end + end + def index today = DateTime.now day = Date.today.wday @@ -211,6 +217,11 @@ class Origami::QuickServiceController < ApplicationController end end + def check_user + if current_user.nil? + redirect_to root_path + end + end # this can always true def check_order_with_booking(booking) if booking.sale.sale_status == "completed" || booking.sale.sale_status == "new" diff --git a/app/controllers/origami/request_bills_controller.rb b/app/controllers/origami/request_bills_controller.rb index aa145b4f..e2553a83 100755 --- a/app/controllers/origami/request_bills_controller.rb +++ b/app/controllers/origami/request_bills_controller.rb @@ -1,5 +1,11 @@ class Origami::RequestBillsController < ApplicationController - + before_action :check_user + + def check_user + if current_user.nil? + redirect_to root_path + end + end # Print Request Bill and add to sale tables def print @sale = Sale.new @@ -13,7 +19,7 @@ class Origami::RequestBillsController < ApplicationController if check_booking.sale_id.nil? # Create Sale if it doesn't exist - @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user) + @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee, current_user, order.source) @sale_data = Sale.find_by_sale_id(@sale_id) @sale_items = SaleItem.where("sale_id=?",@sale_id) else diff --git a/app/controllers/origami/sale_edit_controller.rb b/app/controllers/origami/sale_edit_controller.rb index 72df82ac..1743f881 100755 --- a/app/controllers/origami/sale_edit_controller.rb +++ b/app/controllers/origami/sale_edit_controller.rb @@ -76,11 +76,14 @@ 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) + action_by = current_user.id remark = "FOC 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}Receipt No #{saleObj.receipt_no}" sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,saleObj.cashier_id, action_by,remark,"SALEITEMFOC" ) - saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount) + saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order.source) ProductCommission.create_product_commission(@newsaleitem, saleitemObj) end @@ -141,7 +144,7 @@ class Origami::SaleEditController < BaseOrigamiController end end - saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount) + saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order.source) ProductCommission.edit_product_commission(saleitemObj) end @@ -162,17 +165,21 @@ 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) + action_by = current_user.id remark = "Cancle Void Sale Item ID #{saleitemObj.sale_item_id} | Item Name ->#{saleitemObj.product_name}-Product Code ->#{saleitemObj.product_code}-Instance Code ->#{saleitemObj.item_instance_code}|Receipt No #{saleObj.receipt_no}" sale_audit = SaleAudit.record_audit_for_edit(saleitemObj.sale_id,saleObj.cashier_id, action_by,remark,"ITEMCANCELVOID" ) - saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount) + saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount, order.source) ProductCommission.remove_product_commission(saleitemObj) end # remove all void items def cancel_all_void sale_id = params[:sale_id] + order_source = params[:type] saleObj = Sale.find(sale_id) saleObj.sale_items.each do |item| if item.qty.to_i < 0 @@ -185,13 +192,14 @@ class Origami::SaleEditController < BaseOrigamiController end # re-calc tax - saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount) + saleObj.compute_by_sale_items(saleObj.sale_id, saleObj.sale_items, saleObj.total_discount,order_source) end def apply_void sale_id = params[:sale_id] + order_source = params[:type] saleObj = Sale.find(sale_id) - saleObj.compute_without_void + saleObj.compute_without_void(order_source) saleObj.sale_items.each do |item| ProductCommission.remove_product_commission(item) end diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index d0b73f99..acce6c65 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -3,7 +3,7 @@ class Origami::ShiftsController < BaseOrigamiController end def show - @type = params[:type] + @cashier_type = params[:type] @shift = ShiftSale.current_open_shift(current_user.id) #for bank integration bank_integration = Lookup.collection_of('bank_integration') diff --git a/app/controllers/origami/split_bill_controller.rb b/app/controllers/origami/split_bill_controller.rb index 16239750..e18828fc 100755 --- a/app/controllers/origami/split_bill_controller.rb +++ b/app/controllers/origami/split_bill_controller.rb @@ -3,6 +3,7 @@ class Origami::SplitBillController < BaseOrigamiController def index dining_id = params[:dining_id] + @cashier_type = params[:type] @table = DiningFacility.find(dining_id) @booking = @table.get_booking @orders = Array.new @@ -76,6 +77,7 @@ class Origami::SplitBillController < BaseOrigamiController end def create + cashier_type = params[:cashier_type] order_ids = params[:order_ids] arr_order_ids = nil if !params[:arr_order_ids].nil? @@ -111,7 +113,7 @@ class Origami::SplitBillController < BaseOrigamiController if booking if booking.sale_id.nil? sale = Sale.new - status, sale_id = sale.generate_invoice_from_booking(params[:booking_id], current_user, current_user) + status, sale_id = sale.generate_invoice_from_booking(params[:booking_id], current_user, current_user, cashier_type) sale_data = Sale.find_by_sale_id(sale_id) else status = true @@ -233,7 +235,7 @@ class Origami::SplitBillController < BaseOrigamiController puts "order_id_count < 1" new_order_status = true order_items.each do |order_item| - orderItem = OrderItem.find_by_order_id(order_id) + orderItem = OrderItem.find(order_item["id"]) if !orderItem.nil? if order_item["id"] == orderItem.order_items_id if orderItem.qty.to_f != order_item['qty'].to_f @@ -324,7 +326,7 @@ class Origami::SplitBillController < BaseOrigamiController end sale = Sale.new - status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, current_user) + status, sale_id = sale.generate_invoice_from_booking(booking.booking_id, current_user, current_user, cashier_type) end Promotion.promo_activate(sale) diff --git a/app/controllers/origami/table_invoices_controller.rb b/app/controllers/origami/table_invoices_controller.rb index a84f6ca7..5cd22054 100755 --- a/app/controllers/origami/table_invoices_controller.rb +++ b/app/controllers/origami/table_invoices_controller.rb @@ -31,6 +31,8 @@ class Origami::TableInvoicesController < BaseOrigamiController def show @table = DiningFacility.find(params[:table_id]) + @membership = MembershipSetting::MembershipSetting + @payment_methods = PaymentMethodSetting.all shop = Shop::ShopDetail @sale_array = Array.new @table.bookings.each do |booking| diff --git a/app/controllers/origami/unionpay_controller.rb b/app/controllers/origami/unionpay_controller.rb index 905a1ffb..7213af6d 100644 --- a/app/controllers/origami/unionpay_controller.rb +++ b/app/controllers/origami/unionpay_controller.rb @@ -4,31 +4,40 @@ class Origami::UnionpayController < BaseOrigamiController @cashier_type = params[:type] # limit unionpay_amount sale_data = Sale.find_by_sale_id(@sale_id) - total = sale_data.grand_total + total = 0 @unionpaycount = 0 - others = 0 - @shop = Shop::ShopDetail - if @shop.is_rounding_adj - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - else - new_total = sale_data.grand_total + @rounding_adj = 0 + @can_unionpay = 0 + @member_discount = 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + others = 0 + + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total + + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "unionpay" + @unionpaycount = @unionpaycount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_unionpay = total - @unionpaycount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no end - @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| - if sale_payment.payment_method == "unionpay" - @unionpaycount = @unionpaycount + sale_payment.payment_amount - else - others = others + sale_payment.payment_amount - end - end - @can_unionpay = total - @unionpaycount - others - @member_discount = MembershipSetting.find_by_discount(1) - @sub_total = sale_data.total_amount - @membership_id = sale_data.customer.membership_id - #for bank integration - @receipt_no = sale_data.receipt_no bank_integration = Lookup.collection_of('bank_integration') @bank_integration = 0 if !bank_integration[0].nil? @@ -57,4 +66,9 @@ class Origami::UnionpayController < BaseOrigamiController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/origami/visa_controller.rb b/app/controllers/origami/visa_controller.rb old mode 100755 new mode 100644 index f04ec001..94f58a99 --- a/app/controllers/origami/visa_controller.rb +++ b/app/controllers/origami/visa_controller.rb @@ -4,31 +4,40 @@ class Origami::VisaController < BaseOrigamiController @cashier_type = params[:type] # limit visa_amount sale_data = Sale.find_by_sale_id(@sale_id) - total = sale_data.grand_total + total = 0 @visacount = 0 - others = 0 + @shop = Shop::ShopDetail + @rounding_adj = 0 + @can_visa = 0 + @member_discount = 0 + @sub_total = 0 + @membership_id = nil + @receipt_no = nil + if !sale_data.nil? + total = sale_data.grand_total + others = 0 - @shop = Shop::ShopDetail - if @shop.is_rounding_adj - new_total = Sale.get_rounding_adjustment(sale_data.grand_total) - else - new_total = sale_data.grand_total + if @shop.is_rounding_adj + new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + else + new_total = sale_data.grand_total + end + @rounding_adj = new_total-sale_data.grand_total + + sale_data.sale_payments.each do |sale_payment| + if sale_payment.payment_method == "visa" + @visacount = @visacount + sale_payment.payment_amount + else + others = others + sale_payment.payment_amount + end + end + @can_visa = total - @visacount - others + @member_discount = MembershipSetting.find_by_discount(1) + @sub_total = sale_data.total_amount + @membership_id = sale_data.customer.membership_id + #for bank integration + @receipt_no = sale_data.receipt_no end - @rounding_adj = new_total-sale_data.grand_total - - sale_data.sale_payments.each do |sale_payment| - if sale_payment.payment_method == "visa" - @visacount = @visacount + sale_payment.payment_amount - else - others = others + sale_payment.payment_amount - end - end - @can_visa = total - @visacount - others - @member_discount = MembershipSetting.find_by_discount(1) - @sub_total = sale_data.total_amount - @membership_id = sale_data.customer.membership_id - #for bank integration - @receipt_no = sale_data.receipt_no bank_integration = Lookup.collection_of('bank_integration') @bank_integration = 0 if !bank_integration[0].nil? @@ -57,4 +66,9 @@ class Origami::VisaController < BaseOrigamiController end end + #Shop Name in Navbor + helper_method :shop_detail + def shop_detail + @shop = Shop.first + end end diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index 33ff0d76..74e495ca 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -4,12 +4,13 @@ class Origami::VoidController < BaseOrigamiController sale_id = params[:sale_id] remark = params[:remark] + order_source = params[:type] #tax profile source if Sale.exists?(sale_id) sale = Sale.find_by_sale_id(sale_id) if sale.discount_type == "member_discount" sale.update_attributes(total_discount: 0) - sale.compute_by_sale_items(sale_id, sale.sale_items,0) + sale.compute_by_sale_items(sale_id, sale.sale_items,0,order_source) end # update count for shift sale @@ -86,8 +87,6 @@ class Origami::VoidController < BaseOrigamiController if bookings[0].dining_facility_id.to_i>0 table = DiningFacility.find(bookings[0].dining_facility_id) end - - end if bookings[0].dining_facility_id.to_i > 0 @@ -99,7 +98,7 @@ class Origami::VoidController < BaseOrigamiController end - if ENV["SERVER_MODE"] != "cloud" #no print in cloud server + # if ENV["SERVER_MODE"] != "cloud" #no print in cloud server unique_code = "ReceiptBillPdf" customer= Customer.find(sale.customer_id) @@ -119,9 +118,17 @@ class Origami::VoidController < BaseOrigamiController item_price_by_accounts = SaleItem.calculate_price_by_accounts(sale.sale_items) 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) - end + printer = Printer::ReceiptPrinter.new(print_settings) + filename, sale_receipt_no, printer_name = 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) + result = { + :filepath => filename, + :printer_model => print_settings.brand_name, + :printer_url => print_settings.api_settings + } + + # Mobile Print + render :json => result.to_json + # end #end print diff --git a/app/controllers/print_settings_controller.rb b/app/controllers/print_settings_controller.rb index 710e6ea4..f12778af 100755 --- a/app/controllers/print_settings_controller.rb +++ b/app/controllers/print_settings_controller.rb @@ -64,6 +64,17 @@ class PrintSettingsController < ApplicationController end end + def get_printer_options + printer_name = params[:printer_name] + printer_options = Printer::PrinterWorker.printer_options(printer_name) + options = { + :url => printer_options['device-uri'], + :model => printer_options['printer-info'], + } + + render :json => options.to_json + end + private # Use callbacks to share common setup or constraints between actions. def set_print_setting @@ -72,7 +83,7 @@ class PrintSettingsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def print_setting_params - params.require(:print_setting).permit(:name, :unique_code, :template, :printer_name, :font, :api_settings, :page_width, :page_height, :print_copies,:precision,:delimiter,:heading_space) + params.require(:print_setting).permit(:name, :unique_code, :template, :printer_name, :brand_name, :printer_type, :font, :api_settings, :page_width, :page_height, :print_copies,:precision,:delimiter,:heading_space) end #Shop Name in Navbor diff --git a/app/controllers/reports/saleitem_controller.rb b/app/controllers/reports/saleitem_controller.rb index 796b02ad..24c812eb 100755 --- a/app/controllers/reports/saleitem_controller.rb +++ b/app/controllers/reports/saleitem_controller.rb @@ -15,7 +15,8 @@ class Reports::SaleitemController < BaseReportController shift = ShiftSale.where('shift_started_at = ? and shift_closed_at = ? ',shift_sale.shift_started_at, shift_sale.shift_closed_at) end end - @sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED) + @type = params[:sale_type] + @sale_data, @other_charges,@discount_data , @cash_data , @card_data , @credit_data , @foc_data , @grand_total , @change_amount = Sale.get_by_shift_items(shift_sale_range,shift, from, to, Sale::SALE_STATUS_COMPLETED,@type) @sale_taxes = Sale.get_separate_tax(shift_sale_range,shift,from,to,nil) diff --git a/app/controllers/settings/commissioners_controller.rb b/app/controllers/settings/commissioners_controller.rb index f8314bcb..fb8c1993 100755 --- a/app/controllers/settings/commissioners_controller.rb +++ b/app/controllers/settings/commissioners_controller.rb @@ -1,6 +1,7 @@ class Settings::CommissionersController < ApplicationController load_and_authorize_resource except: [:create] before_action :set_commissioner, only: [:show, :edit, :update, :destroy] + before_action :check_user # GET /commissioners # GET /commissioners.json @@ -82,7 +83,11 @@ class Settings::CommissionersController < ApplicationController end render json: @transactions end - + def check_user + if current_user.nil? + redirect_to root_path + end + end private # Use callbacks to share common setup or constraints between actions. def set_commissioner diff --git a/app/controllers/settings/commissions_controller.rb b/app/controllers/settings/commissions_controller.rb index 5a41de17..1ac6b2cc 100755 --- a/app/controllers/settings/commissions_controller.rb +++ b/app/controllers/settings/commissions_controller.rb @@ -1,6 +1,7 @@ class Settings::CommissionsController < ApplicationController load_and_authorize_resource except: [:create] before_action :set_commission, only: [:show, :edit, :update, :destroy] + before_action :check_user # GET /commissions # GET /commissions.json @@ -68,6 +69,12 @@ class Settings::CommissionsController < ApplicationController # end end + def check_user + if current_user.nil? + redirect_to root_path + end + end + private # Use callbacks to share common setup or constraints between actions. def set_commission diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index 4d7d6026..b7e02fb5 100755 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -8,7 +8,7 @@ class Settings::MenusController < ApplicationController @settings_menus = Menu.all.page(params[:page]).per(10) respond_to do |format| format.html - format.csv { send_data Menu.to_csv } + format.xlsx end end @@ -71,6 +71,14 @@ class Settings::MenusController < ApplicationController # end end + def import + if params[:file] + Menu.import(params[:file]) + redirect_to settings_menus_path, notice: "Menu was successfully Imported" + end + + end + private # Use callbacks to share common setup or constraints between actions. def set_settings_menu diff --git a/app/controllers/settings/order_queue_stations_controller.rb b/app/controllers/settings/order_queue_stations_controller.rb index b6baf64d..adcbc507 100755 --- a/app/controllers/settings/order_queue_stations_controller.rb +++ b/app/controllers/settings/order_queue_stations_controller.rb @@ -1,6 +1,7 @@ class Settings::OrderQueueStationsController < ApplicationController load_and_authorize_resource except: [:create] before_action :set_settings_order_queue_station, only: [:show, :edit, :update, :destroy] + before_action :check_user # GET /settings/order_queue_stations # GET /settings/order_queue_stations.json @@ -67,6 +68,12 @@ class Settings::OrderQueueStationsController < ApplicationController # end end + def check_user + if current_user.nil? + redirect_to root_path + end + end + private # Use callbacks to share common setup or constraints between actions. def set_settings_order_queue_station diff --git a/app/controllers/settings/products_controller.rb b/app/controllers/settings/products_controller.rb index c0be149e..66e8f162 100755 --- a/app/controllers/settings/products_controller.rb +++ b/app/controllers/settings/products_controller.rb @@ -1,6 +1,7 @@ class Settings::ProductsController < ApplicationController load_and_authorize_resource except: [:create] before_action :set_settings_product, only: [:show, :edit, :update, :destroy] + before_action :check_user # GET /settings/products # GET /settings/products.json @@ -65,6 +66,12 @@ load_and_authorize_resource except: [:create] # end end + def check_user + if current_user.nil? + redirect_to root_path + end + end + private # Use callbacks to share common setup or constraints between actions. def set_settings_product diff --git a/app/controllers/settings/promotion_products_controller.rb b/app/controllers/settings/promotion_products_controller.rb index d297fb71..c66761d7 100755 --- a/app/controllers/settings/promotion_products_controller.rb +++ b/app/controllers/settings/promotion_products_controller.rb @@ -1,6 +1,7 @@ class Settings::PromotionProductsController < ApplicationController before_action :set_promotion, only: [:show, :edit, :update, :destroy,:new] before_action :set_promotion_product, only: [:show, :edit, :update, :destroy] + before_action :check_user # GET /promotion_products # GET /promotion_products.json @@ -63,6 +64,12 @@ class Settings::PromotionProductsController < ApplicationController # end end + def check_user + if current_user.nil? + redirect_to root_path + end + end + private # Use callbacks to share common setup or constraints between actions. def set_promotion diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index ec00c5f6..7272ab0c 100755 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -1,6 +1,7 @@ class Settings::PromotionsController < ApplicationController load_and_authorize_resource except: [:create] before_action :set_promotion, only: [:show, :edit, :update, :destroy] + before_action :check_user # GET /promotions # GET /promotions.json @@ -119,6 +120,12 @@ class Settings::PromotionsController < ApplicationController render json: res end + def check_user + if current_user.nil? + redirect_to root_path + end + end + private # Use callbacks to share common setup or constraints between actions. def set_promotion diff --git a/app/controllers/settings/tax_profiles_controller.rb b/app/controllers/settings/tax_profiles_controller.rb index 77414c57..75e4343e 100755 --- a/app/controllers/settings/tax_profiles_controller.rb +++ b/app/controllers/settings/tax_profiles_controller.rb @@ -6,6 +6,18 @@ class Settings::TaxProfilesController < ApplicationController # GET /settings/tax_profiles.json def index @settings_tax_profiles = TaxProfile.all + tax_profiles = Lookup.collection_of("tax_profiles") + if !@settings_tax_profiles.nil? + @settings_tax_profiles.each_with_index do |setting_tax_profile, tax_index| + if !tax_profiles.nil? + tax_profiles.each do |group| + if setting_tax_profile.group_type == group[1] + @settings_tax_profiles[tax_index].group_type = group[0] + end + end + end + end + end end # GET /settings/tax_profiles/1 @@ -15,11 +27,19 @@ class Settings::TaxProfilesController < ApplicationController # GET /settings/tax_profiles/new def new + @name = nil @settings_tax_profile = TaxProfile.new + @tax_profiles = TaxProfile.all end # GET /settings/tax_profiles/1/edit def edit + @settings_tax_profile = TaxProfile.find(params[:id]) + @name = nil + if !@settings_tax_profile.nil? + @name = @settings_tax_profile.name + end + @tax_profiles = TaxProfile.all end # POST /settings/tax_profiles @@ -69,10 +89,20 @@ class Settings::TaxProfilesController < ApplicationController # Use callbacks to share common setup or constraints between actions. def set_settings_tax_profile @settings_tax_profile = TaxProfile.find(params[:id]) + tax_profiles = Lookup.collection_of("tax_profiles") + if !@settings_tax_profile.nil? + if !tax_profiles.nil? + tax_profiles.each do |group| + if @settings_tax_profile.group_type == group[1] + @settings_tax_profile.group_type = group[0] + end + end + end + end end # Never trust parameters from the scary internet, only allow the white list through. def settings_tax_profile_params - params.require(:tax_profile).permit(:name, :rate, :inclusive, :order_by, :created_by) + params.require(:tax_profile).permit(:name, :group_type, :rate, :inclusive, :order_by, :created_by) end end diff --git a/app/controllers/transactions/credit_notes_controller.rb b/app/controllers/transactions/credit_notes_controller.rb index e35baa77..27f52f12 100755 --- a/app/controllers/transactions/credit_notes_controller.rb +++ b/app/controllers/transactions/credit_notes_controller.rb @@ -1,6 +1,7 @@ class Transactions::CreditNotesController < ApplicationController before_action :set_transactions_sale, only: [:show, :edit, :update, :destroy] + before_action :check_user # GET /transactions/sales # GET /transactions/sales.json @@ -25,12 +26,18 @@ class Transactions::CreditNotesController < ApplicationController @credit_notes = 0 end end -puts "sssssssssssss" -puts @credit_notes.to_json + respond_to do |format| format.html # index.html.erb format.json { render json: @credit_notes } end - end - end \ No newline at end of file + end + + def check_user + if current_user.nil? + redirect_to root_path + end + end + +end \ No newline at end of file diff --git a/app/controllers/transactions/orders_controller.rb b/app/controllers/transactions/orders_controller.rb index 17a117bb..c2132ff6 100755 --- a/app/controllers/transactions/orders_controller.rb +++ b/app/controllers/transactions/orders_controller.rb @@ -1,5 +1,7 @@ class Transactions::OrdersController < ApplicationController load_and_authorize_resource except: [:create] + before_action :check_user + def index filter = params[:filter] @@ -21,11 +23,12 @@ class Transactions::OrdersController < ApplicationController @receipt_no = filter @from = from @to = to - + respond_to do |format| - format.html # index.html.erb - format.json { render json: @orders } - end + format.html + format.json { render json: @orders } + # format.csv { send_data OrdersCsvExport.generate } + end end def show @@ -38,4 +41,10 @@ class Transactions::OrdersController < ApplicationController end end + def check_user + if current_user.nil? + redirect_to root_path + end + end + end diff --git a/app/controllers/transactions/sales_controller.rb b/app/controllers/transactions/sales_controller.rb index fafc89f3..be370371 100755 --- a/app/controllers/transactions/sales_controller.rb +++ b/app/controllers/transactions/sales_controller.rb @@ -1,20 +1,30 @@ class Transactions::SalesController < ApplicationController load_and_authorize_resource except: [:create] before_action :set_transactions_sale, only: [:show, :edit, :update, :destroy] + before_action :check_user # GET /transactions/sales # GET /transactions/sales.json def index receipt_no = params[:receipt_no] - from = params[:from] - to = params[:to] + # from = params[:from] + # to = params[:to] + from, to = get_date_range_from_params + @shift = '' + if params[:shift_name].to_i != 0 + @shift = ShiftSale.find(params[:shift_name]) + end if receipt_no.nil? && from.nil? && to.nil? - @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc") + if @shift.blank? + @sales = Sale.where("NOT sale_status='new'").order("sale_id desc") + else + @sales = Sale.where("NOT sale_status='new' and shift_sale_id ='#{@shift.id}'").order("sale_id desc") + end @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) else - sale = Sale.search(receipt_no,from,to) + sale = Sale.search(receipt_no,from,to,@shift) if sale.count > 0 @sales = sale @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) @@ -25,6 +35,12 @@ class Transactions::SalesController < ApplicationController @receipt_no = receipt_no @from = from @to = to + + if @shift.present? + @shift_from = @shift.shift_started_at.nil? ? '-' : @shift.shift_started_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_to = @shift.shift_closed_at.nil? ? '-' : @shift.shift_closed_at.utc.getlocal.strftime("%e %b %I:%M%p") + @shift_data = @shift + end # if receipt_no.nil? && search_date.nil? # @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc").limit(500) @@ -45,6 +61,24 @@ class Transactions::SalesController < ApplicationController # end # end + @sale_audits = [] + @sale_item_audits = [] + if @sales != 0 + @sales.each do |sale| + sale_audit = SaleAudit.where("(action = 'SALEPAYMENT' or action = 'SALEVOID') and sale_id = ? and remark IS NOT NULL",sale.sale_id) + if !sale_audit.nil? + sale_audit.each do |audit| + @sale_audits.push({sale.sale_id => audit.remark}) + end + end + + sale_item_audit = SaleAudit.where("(action LIKE '%ITEM%') and sale_id = ?",sale.sale_id) + if !sale_item_audit.nil? && sale_item_audit.count > 0 + @sale_item_audits.push({sale.sale_id => sale_item_audit.count}) + end + end + end + respond_to do |format| format.html # index.html.erb format.json { render json: @sales } @@ -129,6 +163,80 @@ class Transactions::SalesController < ApplicationController end end + # date range + PERIOD = { + "today" => 0, + "yesterday" => 1, + "this_week" => 2, + "last_week" => 3, + "last_7" => 4, + "this_month" => 5, + "last_month" => 6, + "last_30" => 7, + "this_year" => 8, + "last_year" => 9 + } + + def get_date_range_from_params + period_type = params[:period_type] + period = params[:period] + from = params[:from] + to = params[:to] + day_ref = Time.now.utc.getlocal + + 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 + else + case period.to_i + when PERIOD["today"] + from = day_ref.beginning_of_day.utc + to = day_ref.end_of_day.utc + + when PERIOD["yesterday"] + from = (day_ref - 1.day).beginning_of_day.utc + to = (day_ref - 1.day).end_of_day.utc + + when PERIOD["this_week"] + from = Time.now.beginning_of_week.utc + to = Time.now.utc + when PERIOD["last_week"] + from = (day_ref - 7.day).beginning_of_week.utc + to = (day_ref - 7.day).end_of_week.utc + when PERIOD["last_7"] + from = (day_ref - 7.day).utc + to = Time.now.utc + when PERIOD["this_month"] + from = Time.now.beginning_of_month.utc + to = Time.now.utc + when PERIOD["last_month"] + from = (day_ref - 1.month).beginning_of_month.utc + to = (day_ref - 1.month).end_of_month.utc + when PERIOD["last_30"] + from = (day_ref - 30.day).utc + to = Time.now.utc + when PERIOD["this_year"] + from = Time.now.beginning_of_year.utc + to = Time.now.utc + when PERIOD["last_year"] + from = (day_ref - 1.year).beginning_of_year.utc + to = (day_ref - 1.year).end_of_year.utc + end + end + + return from, to + end + + def check_user + if current_user.nil? + redirect_to root_path + end + end + private # Use callbacks to share common setup or constraints between actions. def set_transactions_sale diff --git a/app/controllers/transactions/shift_sales_controller.rb b/app/controllers/transactions/shift_sales_controller.rb index ce226d30..f3a9fc05 100644 --- a/app/controllers/transactions/shift_sales_controller.rb +++ b/app/controllers/transactions/shift_sales_controller.rb @@ -1,6 +1,7 @@ class Transactions::ShiftSalesController < ApplicationController load_and_authorize_resource except: [:create] before_action :set_transactions_shift_sale, only: [:show, :edit, :update, :destroy] + before_action :check_user def index @@ -53,6 +54,12 @@ class Transactions::ShiftSalesController < ApplicationController end end + def check_user + if current_user.nil? + redirect_to root_path + end + end + private # Use callbacks to share common setup or constraints between actions. def set_transactions_shift_sale diff --git a/app/controllers/transactions/surveys_controller.rb b/app/controllers/transactions/surveys_controller.rb new file mode 100644 index 00000000..b6c48215 --- /dev/null +++ b/app/controllers/transactions/surveys_controller.rb @@ -0,0 +1,28 @@ +class Transactions::SurveysController < ApplicationController + def index + filter = params[:filter] + from = params[:from] + to = params[:to] + + if filter.nil? && from.nil? && to.nil? + surveys = Survey.all + else + surveys = Survey.search(filter,from,to) + end + + if !surveys.nil? + @surveys = Kaminari.paginate_array(surveys).page(params[:page]).per(20) + else + @surveys = [] + end + + @filter = filter + @from = from + @to = to + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @surveys } + end + end +end diff --git a/app/models/ability.rb b/app/models/ability.rb index de43d71f..0b1edcc3 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -105,7 +105,7 @@ class Ability can :show, :home can :read, Order can :update, Order - can :menage, Booking + can :manage, Booking can :manage, OrderQueueStation can :read, Sale can :update, Sale diff --git a/app/models/inventory_definition.rb b/app/models/inventory_definition.rb index 91823068..4634ff73 100755 --- a/app/models/inventory_definition.rb +++ b/app/models/inventory_definition.rb @@ -12,7 +12,7 @@ class InventoryDefinition < ApplicationRecord end def self.find_product_in_inventory(item) - product = InventoryDefinition.find_by_item_code(item.product_code) + product = InventoryDefinition.find_by_item_code(item.item_instance_code) if product.nil? return false, nil else @@ -21,7 +21,7 @@ class InventoryDefinition < ApplicationRecord end def self.check_balance(item,inventory_definition) # item => saleItemOBj - stock = StockJournal.where('item_code=?', item.product_code).order('created_at desc').take + stock = StockJournal.where('item_code=?', item.item_instance_code).order('created_at desc').take unless stock.nil? modify_balance(item, stock, inventory_definition) else diff --git a/app/models/license.rb b/app/models/license.rb index 7d935185..ac82721c 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,7 +1,7 @@ class License include HTTParty - base_uri "connect.smartsales.dev/api" + base_uri "connect.smartsales.asia/api" attr_accessor :name, :address_1, :address_2, :township, :city, :country, :email, :phone, :fax, :logo, :subdomain, :plan_activation_date, :plan_next_renewal_date, :plan_max_products,:plan_max_customers, :plan_active_connections, diff --git a/app/models/menu.rb b/app/models/menu.rb index 052a7042..9f4e6b14 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -1,4 +1,6 @@ class Menu < ApplicationRecord + + require 'spreadsheet' has_many :menu_categories, dependent: :destroy validates_presence_of :name, :valid_days, :valid_time_from, :valid_time_to @@ -33,27 +35,118 @@ class Menu < ApplicationRecord end def self.to_csv - m_attributes = %w{id name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at} - CSV.generate(headers: true) do |csv| + m_attributes = %w{name is_active valid_days valid_time_from valid_time_to created_by created_at updated_at} + CSV.generate(headers: true, row_sep: "\r\n") do |csv| csv << m_attributes menu = Menu.all menu.each do |user| - puts user csv << m_attributes.map{ |attr| user.send(attr)} end end + end - # mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at} - # CSV.generate(headers: true) do |csv| - # csv << m_attributes + def self.import(file) + + spreadsheet = open_spreadsheet(file) + sheet_count = spreadsheet.sheets.count-1 + for i in 0..sheet_count do + header = spreadsheet.sheet(i).row(1) + sheet_name = spreadsheet.sheets[i] - # csv << mc_attributes - # MenuCategory.all.each do |user| - # puts user - # csv << mc_attributes.map{ |attr| user.send(attr)} - # end - # end + (2..spreadsheet.sheet(i).last_row).each do |ii| + row = Hash[[header,spreadsheet.sheet(i).row(ii)].transpose] + if sheet_name == "Account" + # Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) + account = Account.find_by_id(row["id"]) + if account + Account.create(title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) + else + Account.create(id:row["id"], title: row["title"],account_type: row["account_type"],discount: row["discount"],point: row["point"],bonus: row["bonus"],rebate: row["rebate"]) + end + elsif sheet_name == "Item Set" + # ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty]) + item_set = ItemSet.find_by_id(row["id"]) + if item_set + ItemSet.create( name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty]) + else + ItemSet.create(id:row["id"], name: row[name], alt_name: row[alt_name], min_selectable_qty: row[min_selectable_qty], max_selectable_qty: row[max_selectable_qty]) + end + elsif sheet_name == "Menu Item Options" + # MenuItemOption.create(id:row["id"], option_type: row["option_type"],name: row["name"],value: row["value"]) + item_options = MenuItemOption.find_by_id(row["id"]) + if item_options + MenuItemOption.create( option_type: row["option_type"],name: row["name"],value: row["value"]) + else + MenuItemOption.create(id:row["id"], option_type: row["option_type"],name: row["name"],value: row["value"]) + end + elsif sheet_name == "Menu Item Attributes" + # MenuItemAttribute.create(id:row["id"], attribute_type: row["attribute_type"],name: row["name"],value: row["value"]) + item_attributes = MenuItemAttribute.find_by_id(row["id"]) + if item_attributes + MenuItemAttribute.create( attribute_type: row["attribute_type"],name: row["name"],value: row["value"]) + else + MenuItemAttribute.create(id:row["id"], attribute_type: row["attribute_type"],name: row["name"],value: row["value"]) + end + elsif sheet_name == "Menu" + menu = Menu.find_by_id(row["id"]) + if menu + Menu.create(name: row["name"], is_active: row["is_active"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"]) + else + Menu.create(id:row["id"], name: row["name"], is_active: row["is_active"], valid_days: row["valid_days"],valid_time_from: row["valid_time_from"], valid_time_to: row["valid_time_to"], created_by: row["created_by"]) + end + elsif sheet_name == "Menu Category" + # MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"]) + menu_category = MenuCategory.find_by_id(row["id"]) + if menu_category + MenuCategory.create(menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"]) + else + MenuCategory.create(id:row["id"], menu_id: row["menu_id"], code: row["code"], name: row["name"], alt_name: row["alt_name"], order_by: row["order_by"], created_by: row["created_by"], menu_category_id: row["menu_category_id"], is_available: row["is_available"]) + end + elsif sheet_name == "Menu Item" + # MenuItem.create(id:row["id"], item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: row["item_attributes"], item_options: row["item_options"], account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"]) + menu_item = MenuItem.find_by_id(row["id"]) + if menu_item + MenuItem.create(item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: JSON.parse(row["item_attributes"]), item_options: JSON.parse(row["item_options"]), account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"]) + else + MenuItem.create(id:row["id"], item_code: row["item_code"], name: row["name"], alt_name: row["alt_name"], image_path: row["image_path"], description: row["description"], information: row["information"], unit: row["unit"], type: row["type"], menu_category_id: row["menu_category_id"], item_attributes: JSON.parse(row["item_attributes"]), item_options: JSON.parse(row["item_options"]), account_id: row["account_id"], min_qty: row["min_qty"], taxable: row["taxable"], is_sub_item: row["is_sub_item"], is_available: row["is_available"], created_by: row["created_by"]) + end + elsif sheet_name == "Menu Item Instance" + # MenuItemInstance.create(id:row["id"], menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: row["item_attributes"], price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"]) + item_instance = MenuItemInstance.find_by_id(row["id"]) + if item_instance + MenuItemInstance.create(menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: JSON.parse(row["item_attributes"]), price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"]) + else + MenuItemInstance.create(id:row["id"], menu_item_id: row["menu_item_id"].to_i, item_instance_code: row["item_instance_code"], item_instance_name: row["item_instance_name"], item_attributes: JSON.parse(row["item_attributes"]), price: row["price"], is_on_promotion: row["is_on_promotion"], promotion_price: row["promotion_price"], is_available: row["is_available"], is_default: row["is_default"]) + end + elsif sheet_name == "Menu Instance Item Set" + # MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"]) + menu_instance_set = MenuInstanceItemSet.find_by_id(row["id"]) + if menu_instance_set + MenuInstanceItemSet.create(item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"]) + else + MenuInstanceItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_instance_id: row["menu_item_instance_id"]) + end + elsif sheet_name == "Menu Item Set" + # MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"]) + menu_item_set = MenuItemSet.find_by_id(row["id"]) + if menu_item_set + MenuItemSet.create(item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"]) + else + MenuItemSet.create(id:row["id"], item_set_id: row["item_set_id"], menu_item_id: row["menu_item_id"]) + end + end + end + end + + end + def self.open_spreadsheet(file) + case File.extname(file.original_filename) + when ".csv" then Roo::CSV.new(file.path,nil,:ignore) + when ".xls" then Roo::Excel.new(file.path,nil,:ignore) + when ".xlsx" then Roo::Excelx.new(file.path,nil,:ignore) + else raise "Unknown File type: #{original_filename}" + end end end \ No newline at end of file diff --git a/app/models/menu_category.rb b/app/models/menu_category.rb index acb06c4f..666f251a 100755 --- a/app/models/menu_category.rb +++ b/app/models/menu_category.rb @@ -1,7 +1,7 @@ class MenuCategory < ApplicationRecord # before_create :generate_menu_category_code - belongs_to :menu + belongs_to :menu has_many :children, :class_name => "MenuCategory", foreign_key: "menu_category_id" belongs_to :parent, :class_name => "MenuCategory", foreign_key: "menu_category_id", optional: true has_many :menu_items @@ -83,4 +83,19 @@ class MenuCategory < ApplicationRecord # def generate_menu_category_code # self.code = SeedGenerator.generate_code(self.class.name, "C") # end + + def self.to_csv + + mc_attributes = %w{id menu_id code name alt_name order_by created_by menu_category_id is_available created_at updated_at} + CSV.generate(headers: true) do |csv| + csv << mc_attributes + + csv << mc_attributes + MenuCategory.all.each do |user| + puts user + csv << mc_attributes.map{ |attr| user.send(attr)} + end + end + + end end diff --git a/app/models/order.rb b/app/models/order.rb index 25c5db4a..fcc8b6c2 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -71,9 +71,9 @@ class Order < ApplicationRecord BookingOrder.create({:booking_id => booking.booking_id, :order => self}) #Send order to queue one it done! - if self.source != "quick_service" + # if self.source != "quick_service" process_order_queue - end + # end #send order to broadcast job send_order_broadcast(booking) @@ -297,7 +297,7 @@ class Order < ApplicationRecord else if order oqs = OrderQueueStation.new - oqs.process_order(order, self.table_id) + oqs.process_order(order, self.table_id, self.source) end assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) ActionCable.server.broadcast "order_queue_station_channel",order: assign_order @@ -313,7 +313,7 @@ class Order < ApplicationRecord else if order oqs = OrderQueueStation.new - oqs.process_order(order, self.table_id) + oqs.process_order(order, self.table_id, self.source) end assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) ActionCable.server.broadcast "order_queue_station_channel",order: assign_order @@ -326,7 +326,7 @@ class Order < ApplicationRecord else if order oqs = OrderQueueStation.new - oqs.process_order(order, self.table_id) + oqs.process_order(order, self.table_id, self.source) end assign_order = AssignedOrderItem.assigned_order_item_by_job(self.id) ActionCable.server.broadcast "order_queue_station_channel",order: assign_order diff --git a/app/models/order_item.rb b/app/models/order_item.rb index 776bb94c..87d60e63 100755 --- a/app/models/order_item.rb +++ b/app/models/order_item.rb @@ -5,7 +5,8 @@ class OrderItem < ApplicationRecord before_create :generate_custom_id #Associations - belongs_to :order, autosave: true + belongs_to :order, autosave: true + # belongs_to :order, counter_cache: true #Validation validates_presence_of :item_code, :item_name, :qty diff --git a/app/models/order_queue_station.rb b/app/models/order_queue_station.rb index af544ce5..889491ed 100755 --- a/app/models/order_queue_station.rb +++ b/app/models/order_queue_station.rb @@ -13,7 +13,7 @@ class OrderQueueStation < ApplicationRecord # validations validates_presence_of :station_name, :printer_name - def process_order (order, table_id) + def process_order (order, table_id, order_source = nil) oqs_stations = OrderQueueStation.active @@ -55,7 +55,7 @@ class OrderQueueStation < ApplicationRecord end end - if oqs.auto_print + if oqs.auto_print && order_source != "quick_service" if oqs_order_items.length > 0 print_slip(oqs, order, oqs_order_items) is_auto_printed = true @@ -90,7 +90,81 @@ class OrderQueueStation < ApplicationRecord end end - if oqs.auto_print + if oqs.auto_print && order_source != "quick_service" + if oqs_order_items.length > 0 + print_slip(oqs, order, oqs_order_items) + is_auto_printed = true + end + end + end + end + end #end else + end + + def pay_process_order_queue (order_id, table_id) + + oqs_stations = OrderQueueStation.active + + order = Order.find(order_id) + order_items = order.order_items + + if table_id.to_i > 0 + # get dining + dining = DiningFacility.find(table_id) + oqs_by_zones = OrderQueueProcessByZone.where("zone_id=#{dining.zone_id}") + booking = Booking.find_by_dining_facility_id(dining.id) + + # ToDo per item per printer + + oqs_by_zones.each do |oqpbz| + oqs = OrderQueueStation.find(oqpbz.order_queue_station_id) + 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 (order_item.qty > 0) + 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 + end + else + 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 (order_item.qty > 0) + 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 diff --git a/app/models/print_setting.rb b/app/models/print_setting.rb index d28b852b..a3cfc597 100755 --- a/app/models/print_setting.rb +++ b/app/models/print_setting.rb @@ -1,6 +1,6 @@ class PrintSetting < ApplicationRecord # validations - validates_presence_of :name, :unique_code, :printer_name, :page_width, :page_height, :print_copies + validates_presence_of :name, :unique_code, :printer_name, :brand_name, :api_settings, :page_width, :page_height, :print_copies def self.get_precision_delimiter PrintSetting.find_by_unique_code("ReceiptBillPdf") diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index c0485187..2924853e 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -24,6 +24,11 @@ class Printer::PrinterWorker end end + # Options from printer name + def self.printer_options(printer_name) + Cups.options_for(printer_name) + end + def self.printers() Cups.show_destinations end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index abc4c49c..447543f2 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -176,7 +176,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker 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 + #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) receipt_bill_a5_pdf = Lookup.collection_of("print_settings") #print_settings with name:ReceiptBillA5Pdf if !receipt_bill_a5_pdf.empty? @@ -202,14 +202,14 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker begin if count == 1 - filename = "/receipts/receipt_bill_#{sale_data.receipt_no}.pdf" - pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf" + filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf" + pdf.render_file filename if printed_status != 'Paid' self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}.pdf", cashier_terminal.printer_name) end else - filename = "/receipts/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" - pdf.render_file directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" + filename = directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf" + pdf.render_file filename if printed_status != 'Paid' self.print(directory_name + "/receipt_bill_#{sale_data.receipt_no}_#{count}.pdf", cashier_terminal.printer_name) end @@ -272,11 +272,11 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker def print_receipt_pdf(filename,receipt_no,print_copies,printer_name) count = print_copies.to_i # if count == 0 - # self.print("public"+filename, printer_name) + # self.print(filename, printer_name) # else begin if count == 1 - self.print("public"+filename, printer_name) + self.print(filename, printer_name) else filename = "public/receipts/receipt_bill_#{receipt_no}_#{count}.pdf" self.print(filename, printer_name) diff --git a/app/models/sale.rb b/app/models/sale.rb index 5d46aafc..970896bf 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -26,7 +26,7 @@ class Sale < ApplicationRecord SALE_STATUS_OUTSTANDING = "outstanding" SALE_STATUS_COMPLETED = "completed" - def generate_invoice_from_booking(booking_id, requested_by, cashier) + def generate_invoice_from_booking(booking_id, requested_by, cashier, order_source = nil) booking = Booking.find(booking_id) status = false Rails.logger.debug "Booking -> " + booking.id.to_s @@ -36,9 +36,9 @@ class Sale < ApplicationRecord booking.booking_orders.each do |order| if booking.sale_id - status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by, cashier) + status, sale_id = generate_invoice_from_order(order.order_id, nil, booking, requested_by, cashier, order_source) else - status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by, cashier) + status, sale_id = generate_invoice_from_order(order.order_id, booking.sale_id, booking, requested_by, cashier, order_source) end booking.sale_id = sale_id end @@ -58,7 +58,7 @@ class Sale < ApplicationRecord end end - def generate_invoice_from_order (order_id, sale_id, booking, requested_by, cashier = nil) + def generate_invoice_from_order (order_id, sale_id, booking, requested_by, cashier = nil, order_source = nil) taxable = true #if sale_id is exsit and validate #add order to that invoice @@ -128,7 +128,7 @@ class Sale < ApplicationRecord self.save! #compute sales summary - compute + compute(order_source) #Update the order items that is billed order.update_items_status_to_billed(nil) @@ -172,7 +172,7 @@ class Sale < ApplicationRecord # Create Sale if it doesn't exist # puts "current_login_employee" # puts current_login_employee.name - @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee,current_user) + @status, @sale_id = @sale.generate_invoice_from_booking(check_booking.id,current_login_employee,current_user,order.source) @sale_data = Sale.find_by_sale_id(@sale_id) @sale_items = SaleItem.where("sale_id=?",@sale_id) else @@ -310,7 +310,7 @@ class Sale < ApplicationRecord end #compute - invoice total - def compute + def compute(order_source = nil) sales_items = self.sale_items #Computation Fields @@ -329,7 +329,7 @@ class Sale < ApplicationRecord # total_taxable = total_taxable + (item.taxable_price * item.qty) end - apply_tax (total_taxable) + apply_tax(total_taxable, order_source) self.total_amount = subtotal_price self.total_discount = total_discount @@ -342,8 +342,7 @@ class Sale < ApplicationRecord end #compute - invoice total - def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil) - + def compute_by_sale_items(sale_id, sale_itemss, total_discount,discount_type=nil,order_source=nil) sale = Sale.find(sale_id) sales_items = sale_itemss @@ -362,7 +361,6 @@ class Sale < ApplicationRecord end end - compute_tax(sale, total_taxable, total_discount) sale.total_amount = subtotal_price sale.total_discount = total_discount sale.grand_total = (sale.total_amount - sale.total_discount) + sale.total_tax @@ -371,12 +369,15 @@ class Sale < ApplicationRecord end #compute rounding adjustment # adjust_rounding - sale.save! + sale.rounding_adjustment = compute_adjust_rounding(sale.grand_total) + compute_tax(sale, total_taxable, total_discount, order_source) + + sale.save! end # No Use too many wrong - def compute_without_void + def compute_without_void(order_source = nil) sales_items = self.sale_items #Computation Fields @@ -396,7 +397,7 @@ class Sale < ApplicationRecord end end - apply_tax (total_taxable) + apply_tax(total_taxable, order_source) self.total_amount = subtotal_price self.total_discount = total_discount self.grand_total = (self.total_amount - self.total_discount) + self.total_tax @@ -407,7 +408,7 @@ class Sale < ApplicationRecord end # Tax Re-Calculte - def compute_tax(sale, total_taxable, total_discount = 0) + def compute_tax(sale, total_taxable, total_discount = 0, order_source = nil) shop = Shop.first(); #if tax is not apply create new record @@ -423,8 +424,9 @@ class Sale < ApplicationRecord # #Creat new tax records if sale.payment_status != 'foc' tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax.to_i == tax.id + # customer.tax_profiles.each do |cus_tax| + # if cus_tax.to_i == tax.id + if tax.group_type.to_s == order_source.to_s sale_tax = SaleTax.new(:sale => sale) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -447,15 +449,17 @@ class Sale < ApplicationRecord sale_tax.inclusive = tax.inclusive sale_tax.save - end end + # end + # end end end + sale.total_tax = total_tax_amount end # Tax Calculate - def apply_tax(total_taxable) + def apply_tax(total_taxable, order_source = nil) shop = Shop.first(); #if tax is not apply create new record @@ -469,11 +473,14 @@ class Sale < ApplicationRecord tax_profiles = TaxProfile.all.order("order_by asc") customer = Customer.find(self.customer_id) - + if order_source.to_s == "emenu" + order_source = "cashier" + end #Create new tax records tax_profiles.each do |tax| - customer.tax_profiles.each do |cus_tax| - if cus_tax.to_i == tax.id + # customer.tax_profiles.each do |cus_tax| + # if cus_tax.to_i == tax.id + if tax.group_type.to_s == order_source.to_s sale_tax = SaleTax.new(:sale => self) sale_tax.tax_name = tax.name sale_tax.tax_rate = tax.rate @@ -497,8 +504,9 @@ class Sale < ApplicationRecord sale_tax.inclusive = tax.inclusive sale_tax.save - end end + # end + # end end self.total_tax = total_tax_amount end @@ -546,6 +554,26 @@ class Sale < ApplicationRecord end + def compute_adjust_rounding(grand_total) + shop_details = Shop::ShopDetail + # rounding adjustment + if shop_details.is_rounding_adj + a = grand_total % 25 # Modulus + b = grand_total / 25 # Division + #not calculate rounding if modulus is 0 and division is even + #calculate rounding if modulus is zero or not zero and division are not even + if (a != 0.0 && b%2 != 0.0) || (a==0.0 && b%2 !=0) + new_total = Sale.get_rounding_adjustment(grand_total) + rounding_adjustment = new_total - grand_total + else + rounding_adjustment = 0.00 + end + else + rounding_adjustment = 0.00 + end + return rounding_adjustment + end + #Generate new Receipt No when it is not assigned def generate_receipt_no #shop_code and client_code @@ -570,7 +598,7 @@ class Sale < ApplicationRecord end end - def self.search(filter,from,to) + def self.search(filter,from,to,shift) if filter.blank? keyword = '' else @@ -578,10 +606,18 @@ class Sale < ApplicationRecord end if from.present? && to.present? - sale = Sale.where("DATE_FORMAT(receipt_date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(receipt_date,'%d-%m-%Y') <= ? and NOT sale_status = 'void' ", from,to) - query = sale.where(keyword) + if shift.blank? + sale = Sale.where("DATE_FORMAT(receipt_date,'%Y-%m-%d') >= ?" + " AND DATE_FORMAT(receipt_date,'%Y-%m-%d') <= ? and NOT sale_status = 'new' ", from,to) + else + sale = Sale.where("DATE_FORMAT(receipt_date,'%Y-%m-%d') >= ?" + " AND DATE_FORMAT(receipt_date,'%Y-%m-%d') <= ? and NOT sale_status = 'new' and shift_sale_id = '#{shift.id}'", from,to) + end + query = sale.where(keyword) else + if shift.blank? where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%") + else + where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}' and shift_sale_id = ?","%#{filter}%","%#{filter}%",shift.id) + end end end @@ -770,12 +806,27 @@ def self.get_by_shift_sale(from,to,status) return query = query.where("shift_sales.shift_started_at >= ?" + " AND shift_sales.shift_closed_at <= ?", from,to) 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," + +def self.get_item_query(type) + + if type == "revenue" || type.nil? + sale_type = "i.status IS NULL and i.qty >0 " + elsif type == "all" + sale_type = "" + elsif type == "discount" + sale_type = "i.status = 'Discount'" + elsif type == "foc" + sale_type = "i.status = 'foc' and i.qty > 0" + elsif type == "void" + sale_type = "i.status = 'void' and i.qty > 0" + elsif type == "other" + sale_type = "i.item_instance_code IS NULL" + end + 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.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 ") + "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 ") query = query.joins("JOIN sale_items i ON i.sale_id = sales.sale_id" + " JOIN menu_item_instances mii ON i.item_instance_code = mii.item_instance_code" + @@ -784,7 +835,7 @@ def self.get_item_query() " JOIN menu_categories mc ON mc.id = mi.menu_category_id ") # "JOIN employee_accesses ea ON ea.`employee_id` = sales.cashier_id ") query = query.joins(" JOIN accounts acc ON acc.id = mi.account_id") - # query = query.where("i.item_instance_code IS NOT NULL") + query = query.where("#{sale_type}") query = query.group("acc.title,mi.account_id,mi.menu_category_id,i.product_name,i.unit_price") .order("acc.title desc, mi.account_id desc, mi.menu_category_id desc, i.unit_price asc") end @@ -799,10 +850,15 @@ def self.get_other_charges() query = query.group("i.sale_item_id") end -def self.get_by_shift_items(shift_sale_range, shift, from, to, status) +def self.get_by_shift_items(shift_sale_range, shift, from, to, status,type) # date_type_selection = get_sql_function_for_report_type(report_type) - query = self.get_item_query() - + if type == "other" + other_charges = self.get_other_charges() + query = self.get_item_query(type) + else + query = self.get_item_query(type) + end + discount_query = 0 total_card_amount = 0 total_cash_amount = 0 @@ -886,7 +942,7 @@ def self.get_menu_item_query(order_by) "(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 CONCAT(menu_items.name,' - ',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, + " menu_category_name,mc.id as menu_category_id, si.status 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" + @@ -1106,88 +1162,319 @@ end return tax end - def self.top_products(today,from,to) + def self.top_products(today,current_user,from,to,from_time,to_time) if !from.nil? && !to.nil? - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + if current_user.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") + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed'") + end + query = query.group('mi.name') + .order("SUM(i.qty) DESC").limit(20) + else + if current_user.role == 'administrator' || current_user.role == 'manager' + 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 sale_status= 'completed'") - .group('mi.name') - .order("SUM(i.qty) DESC").limit(20) + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed'") + end + query = query.group('mi.name') + .order("SUM(i.qty) DESC").limit(20) + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.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") + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + end + query = query.group('mi.name') + .order("SUM(i.qty) DESC").limit(20) + end + end + end else - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + if current_user.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 DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ - "and sale_status= 'completed'") + " and sale_status= 'completed'") .group('mi.name') .order("SUM(i.qty) DESC").limit(20) + else + if current_user.role == 'administrator' || current_user.role == 'manager' + 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 sale_status= 'completed'") + .group('mi.name') + .order("SUM(i.qty) DESC").limit(20) + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.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 DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ + " and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + .group('mi.name') + .order("SUM(i.qty) DESC").limit(20) + end + end + end end end - def self.bottom_products(today,from,to) + def self.bottom_products(today,current_user,from,to,from_time,to_time) 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 sale_status= 'completed'") - .group('mi.name') + if current_user.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") + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed'") + end + query = query.group('mi.name') .order("SUM(i.qty) ASC").limit(20) + else + if current_user.role == 'administrator' || current_user.role == 'manager' + 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") + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed'") + end + query = query.group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.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") + if !from_time.nil? && !to_time.nil? + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'"+ + " and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + else + query = query.where("(i.qty > 0 and i.price > 0) and DATE_FORMAT(CONVERT_TZ(receipt_date,'+00:00','+06:30') between '#{from}' and '#{to}'"+ + " and sale_status= 'completed' and shift_sale_id='#{shift.id}'") + end + query = query.group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + end + end + end else - query = Sale.select("(SUM(i.qty) * i.price) as grand_total,SUM(i.qty) as total_item," + + if current_user.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 DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ "and sale_status= 'completed'") .group('mi.name') .order("SUM(i.qty) ASC").limit(20) + else + if current_user.role == 'administrator' || current_user.role == 'manager' + 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 sale_status= 'completed'") + .group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.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 DATE_FORMAT(receipt_date,'%Y-%m-%d') = '#{today}'"+ + " and sale_status= 'completed' and shift_sale_id=#{shift.id}") + .group('mi.name') + .order("SUM(i.qty) ASC").limit(20) + end + end + end end end - def self.hourly_sales(today,from,to) + def self.hourly_sales(today,current_user,from,to,from_time,to_time) if !from.nil? && !to.nil? - query= Sale.select("grand_total") - .where('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') + if current_user.nil? + query = Sale.select("grand_total") + if !from_time.nil? && !to_time.nil? + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + else + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + end + query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .order('receipt_date') + else + if current_user.role == 'administrator' || current_user.role == 'manager' + query = Sale.select("grand_total") + if !from_time.nil? && !to_time.nil? + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + else + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + end + query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .order('receipt_date') + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("grand_total") + if !from_time.nil? && !to_time.nil? + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) + else + query = query.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) + end + query = query.group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .order('receipt_date') + end + end + end else - query= Sale.select("grand_total") + if current_user.nil? + query = Sale.select("grand_total") .where('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') + else + if current_user.role == 'administrator' || current_user.role == 'manager' + query = Sale.select("grand_total") + .where('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') + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + query = Sale.select("grand_total") + .where('sale_status = "completed" and DATE_FORMAT(receipt_date,"%Y-%m-%d") = ? and shift_sale_id=?',today,shift.id) + .group("date_format(CONVERT_TZ(receipt_date,'+00:00', 'SYSTEM'), '%I %p')") + .order('receipt_date') + end + end + end end end - def self.employee_sales(today,from,to) + def self.employee_sales(today,current_user,from,to,from_time,to_time) if !from.nil? && !to.nil? - query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") + if current_user.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") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") + else + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") + end + query = query.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 + if current_user.role == 'administrator' || current_user.role == 'manager' + 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") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") + else + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") + end + query = query.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 + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.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") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}' and shift_sale_id='#{shift.id}'") + else + query = query.where("sales.payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and shift_sale_id='#{shift.id}'") + end + query = query.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 + end else - query = Sale.joins("JOIN employees as e on e.id=sales.cashier_id") + if current_user.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 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,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' || current_user.role == 'manager' - total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).sum("grand_total") + 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") 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) + 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}' and shift_sale_id='#{shift.id}'") + .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 + end + end + end + + def self.total_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + if !from.nil? && !to.nil? + if current_user.nil? + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).sum("grand_total") + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to).sum("grand_total") + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).sum("grand_total") + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to).sum("grand_total") + end + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) .sum("grand_total") + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) + .sum("grand_total") + end end end end @@ -1208,17 +1495,29 @@ end end end - def self.total_count(today,current_user=nil,from=nil,to=nil) + def self.total_count(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? - total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).count + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to).count + end else if current_user.role == 'administrator' || current_user.role == 'manager' - total = Sale.where('sale_status = "completed" and receipt_date between ? and ?',from,to).count + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time).count + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to).count + end 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 + if !from_time.nil? && !to_time.nil? + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? and shift_sale_id = ?',from,to,from_time,to_time,shift.id).count + else + total = Sale.where('sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id = ?',from,to,shift.id).count + end end end end @@ -1238,23 +1537,41 @@ end end end - def self.total_card_sale(today,current_user=nil,from=nil,to=nil) + def self.total_card_sale(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=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' || current_user.role == 'manager' - 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) + if !from_time.nil? && !to_time.nil? + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") 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,from_time,to_time) .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) + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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") + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") 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,from_time,to_time) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + else + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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") + end + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + if !from_time.nil? && !to_time.nil? + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") 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,from_time,to_time,shift.id) + .joins("JOIN sale_payments sp ON sp.sale_id = sales.sale_id") + .sum("sp.payment_amount") + else + query = Sale.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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 end @@ -1280,23 +1597,41 @@ end end end - def self.credit_payment(today,current_user=nil,from=nil,to=nil) + def self.credit_payment(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=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' || current_user.role == 'manager' - query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and s.receipt_date between ? and ?',from,to) + if !from_time.nil? && !to_time.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) .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) + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") .sum("payment_amount") + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + else + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + end + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + if !from_time.nil? && !to_time.nil? + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and s.shift_sale_id=?',from,to,from_time,to_time,shift.id) + .joins("INNER JOIN sales s ON s.sale_id = sale_payments.sale_id") + .sum("payment_amount") + else + query = SalePayment.where('s.sale_status = "completed" and payment_method="creditnote" and DATE_FORMAT(CONVERT_TZ(s.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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 end @@ -1322,23 +1657,41 @@ end end end - def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil) + def self.summary_sale_receipt(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=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) + if !from_time.nil? && !to_time.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(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) .first() + else + 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(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .first() + end else if current_user.role == 'administrator' || current_user.role == 'manager' - 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() + if !from_time.nil? && !to_time.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(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + .first() + else + 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(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .first() + end 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() + if !from_time.nil? && !to_time.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(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and shift_sale_id=?',from,to,from_time,to_time,shift.id) + .first() + else + 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(CONVERT_TZ(receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and shift_sale_id=?',from,to,shift.id) + .first() + end end end end @@ -1364,23 +1717,41 @@ end end end - def self.total_payment_methods(today,current_user=nil,from=nil,to=nil) + def self.total_payment_methods(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=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) + if !from_time.nil? && !to_time.nil? + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + end else if current_user.role == 'administrator' || current_user.role == 'manager' - query = Sale.select("distinct sp.payment_method") - .where('sales.sale_status = "completed" and sales.receipt_date between ? and ?',from,to) + if !from_time.nil? && !to_time.nil? + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + end 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") + if !from_time.nil? && !to_time.nil? + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + .joins("JOIN sale_payments as sp ON sp.sale_id = sales.sale_id") + else + query = Sale.select("distinct sp.payment_method") + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") 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 end @@ -1406,35 +1777,69 @@ end end end - def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil) + def self.payment_sale(payment_method, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + time_query = '' + if !from_time.nil? && !to_time.nil? + time_query = " and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'" + end 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' || current_user.role == 'manager' + if !from_time.nil? && !to_time.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) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") 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,from_time,to_time) else - query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and sales.receipt_date between ? and ?",from,to) + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) 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(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") 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 DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') 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() + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.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) + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") 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,from_time,to_time) 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) + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) 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 + 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(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") 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 DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') 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() + end + else + shift = ShiftSale.current_open_shift(current_user.id) + if !shift.nil? + if !from_time.nil? && !to_time.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(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%H:%M") 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,from_time,to_time,shift.id) + else + query = query.where("sales.sale_status = 'completed' and sp.payment_method = '#{payment_method}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,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() + else + 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(CONVERT_TZ(sales.receipt_date, "+00:00", "+06:30"),"%Y-%m-%d") 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 DATE_FORMAT(CONVERT_TZ(sales.receipt_date, '+00:00', '+06:30'),'%Y-%m-%d') 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 end @@ -1472,10 +1877,10 @@ 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) + def self.total_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) + dinein_cnt = self.total_dinein(today,current_user,from,to,from_time,to_time) + takeaway_cnt = self.total_takeaway(today,current_user,from,to,from_time,to_time) + membership_cnt = self.total_membership(today,current_user,from,to,from_time,to_time) total_cus = 0 if !dinein_cnt.nil? || !takeaway_cnt.nil? || !membership_cnt.nil? @@ -1485,26 +1890,47 @@ end return total_cus end - def self.total_dinein(today,current_user=nil,from=nil,to=nil) + def self.total_dinein(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=nil) if !from.nil? && !to.nil? if current_user.nil? - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + if !from_time.nil? && !to_time.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) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to,from_time,to_time) .first() + else + 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(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to) + .first() + end else if current_user.role == 'administrator' || current_user.role == 'manager' - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + if !from_time.nil? && !to_time.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) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to,from_time,to_time) .first() + else + 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(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null',from,to) + .first() + end else shift = ShiftSale.current_open_shift(current_user.id) if !shift.nil? - query = Sale.select("count(sales.customer_id) as total_dinein_cus") + if !from_time.nil? && !to_time.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) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Dinein" and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) .first() + else + 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(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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 end @@ -1533,26 +1959,47 @@ end end end - def self.total_takeaway(today,current_user=nil,from=nil,to=nil) + def self.total_takeaway(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=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' || current_user.role == 'manager' + if !from_time.nil? && !to_time.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) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZsales.receipt_date,"%H:%M") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to,from_time,to_time) .first() + else + 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(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to) + .first() + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.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(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to,from_time,to_time) + .first() + else + 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(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null',from,to) + .first() + end 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() + if !from_time.nil? && !to_time.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(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type = "Takeaway" and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + .first() + else + 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(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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 end @@ -1581,26 +2028,43 @@ end end end - def self.total_membership(today,current_user=nil,from=nil,to=nil) + def self.total_membership(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=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' || current_user.role == 'manager' + if !from_time.nil? && !to_time.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) + .where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") 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,from_time,to_time) .first() + else + 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(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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() + end + else + if current_user.role == 'administrator' || current_user.role == 'manager' + if !from_time.nil? && !to_time.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(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") 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,from_time,to_time) + .first() + else + 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(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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() + end 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() + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") 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,from_time,to_time,shift.id).first() + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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 end @@ -1629,26 +2093,41 @@ end end end - def self.total_other_customer(today,current_user=nil,from=nil,to=nil) + def self.total_other_customer(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=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() + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time) + .first() + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null',from,to) + .first() + end else if current_user.role == 'administrator' || current_user.role == 'manager' 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() + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type is null and c.membership_id is null',from,to,from_time,to_time) + .first() + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and c.customer_type is null and c.membership_id is null',from,to) + .first() + end 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() + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and c.customer_type is null and c.membership_id is null and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + .first() + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") 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 end @@ -1677,29 +2156,44 @@ end end end - def self.total_order(today,current_user=nil,from=nil,to=nil) + def self.total_order(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=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() + if !from_time.nil? && !to_time.nil? + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + .first() + else + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .first() + end else if current_user.role == 'administrator' || current_user.role == 'manager' 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() + if !from_time.nil? && !to_time.nil? + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + .first() + else + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + .first() + end 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() + if !from_time.nil? && !to_time.nil? + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + .first() + else + query = query.where('b.status = "billed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) + .first() + end end end end @@ -1731,26 +2225,38 @@ end end end - def self.total_account(today,current_user=nil,from=nil,to=nil) + def self.total_account(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=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) + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to,from_time,to_time) + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + end else if current_user.role == 'administrator' || current_user.role == 'manager' 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) + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ?',from,to,from_time,to_time) + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ?',from,to) + end 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) + if !from_time.nil? && !to_time.nil? + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%H:%M") between ? and ? and sales.shift_sale_id=?',from,to,from_time,to_time,shift.id) + else + query = query.where('sales.sale_status = "completed" and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,"+00:00","+06:30"),"%Y-%m-%d") between ? and ? and sales.shift_sale_id=?',from,to,shift.id) + end end end end @@ -1779,26 +2285,41 @@ end end end - def self.account_data(account_id, today, current_user=nil,from=nil,to=nil) + def self.account_data(account_id, today, current_user=nil,from=nil,to=nil,from_time=nil,to_time=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() + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + .first() + else + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + .first() + end else if current_user.role == 'administrator' || current_user.role == 'manager' 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() + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + .first() + else + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + .first() + end 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() + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) + .first() + else + query = query.where("sales.sale_status = 'completed' and a.account_id ='#{account_id}' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + .first() + end end end end @@ -1827,32 +2348,44 @@ end end end - def self.top_items(today,current_user=nil,from=nil,to=nil) + def self.top_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=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() + if !from_time.nil? && !to_time.nil? + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + else + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + end + query = query.group("a.product_code") + .order("SUM(a.qty) DESC") + .first() else if current_user.role == 'administrator' || current_user.role == 'manager' 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() + if !from_time.nil? && !to_time.nil? + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + else + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + end + query = query.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() + if !from_time.nil? && !to_time.nil? + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) + else + query = query.where("(a.qty > 0 and a.price > 0) and payment_status='paid' and sales.sale_status = 'completed' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + end + query = query.group("a.product_code") + .order("SUM(a.qty) DESC") + .first() end end end @@ -1887,23 +2420,38 @@ end end end - def self.total_foc_items(today,current_user=nil,from=nil,to=nil) + def self.total_foc_items(today,current_user=nil,from=nil,to=nil,from_time=nil,to_time=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") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + .sum("a.qty") + else + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + .sum("a.qty") + end else if current_user.role == 'administrator' || current_user.role == 'manager' 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") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ?",from,to,from_time,to_time) + .sum("a.qty") + else + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ?",from,to) + .sum("a.qty") + end 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") + if !from_time.nil? && !to_time.nil? + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%H:%M') between ? and ? and sales.shift_sale_id=?",from,to,from_time,to_time,shift.id) + .sum("a.qty") + else + query = query.where("sales.sale_status = 'completed' and a.remark='foc' and a.product_name not like '%FOC%' and DATE_FORMAT(CONVERT_TZ(sales.receipt_date,'+00:00','+06:30'),'%Y-%m-%d') between ? and ? and sales.shift_sale_id=?",from,to,shift.id) + .sum("a.qty") + end end end end @@ -1963,7 +2511,7 @@ end end # Re-compute for add - saleobj.compute + saleobj.compute(order.source) saleobj.save order.save booking.save @@ -1993,7 +2541,7 @@ end end # Re-compute for add - saleobj.compute + saleobj.compute(order.source) saleobj.save order.save booking.save diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 5809dc0f..3ff4697e 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -11,6 +11,7 @@ class SalePayment < ApplicationRecord def process_payment(invoice, action_by, cash_amount, payment_method,remark=nil) self.sale = invoice self.received_amount = cash_amount + self.payment_reference = remark amount_due = invoice.grand_total #get all payment for this invoices @@ -48,6 +49,8 @@ class SalePayment < ApplicationRecord payment_status = paypar_payment when "foc" payment_status = foc_payment + when "JunctionPay" + payment_status = junction_pay_payment else puts "it was something else" end @@ -205,8 +208,7 @@ class SalePayment < ApplicationRecord self.outstanding_amount = self.sale.grand_total.to_f - self.received_amount.to_f self.payment_status = "paid" payment_method = self.save! - sale_update_payment_status(self.received_amount) - + sale_update_payment_status(self.received_amount) return payment_status end @@ -297,6 +299,22 @@ class SalePayment < ApplicationRecord end + def junction_pay_payment + payment_status = false + + #Next time - validate if the vochure number is valid - within + self.payment_method = "JunctionPay" + self.payment_amount = self.received_amount + # self.payment_reference = self.payment_reference + self.outstanding_amount = self.sale.grand_total- self.received_amount + self.payment_status = "paid" + payment_method = self.save! + sale_update_payment_status(self.received_amount) + + return payment_status + + end + def sale_update_payment_status(paid_amount,check_foc = false) #update amount_outstanding self.sale.amount_received = self.sale.amount_received.to_f + paid_amount.to_f @@ -306,6 +324,7 @@ class SalePayment < ApplicationRecord sObj = Sale.find(self.sale_id) is_credit = 0 is_foc = 0 + method_status = false sObj.sale_payments.each do |spay| all_received_amount += spay.payment_amount.to_f if spay.payment_method == "creditnote" @@ -314,8 +333,12 @@ class SalePayment < ApplicationRecord if spay.payment_method == "foc" is_foc = 1 end + if spay.payment_method == "cash" || spay.payment_method == "foc" || spay.payment_method == "creditnote" + method_status = true + end end - if (self.sale.grand_total <= all_received_amount) + + if (self.sale.grand_total <= all_received_amount) && method_status if is_credit == 0 self.sale.payment_status = "paid" else @@ -355,11 +378,15 @@ class SalePayment < ApplicationRecord end self.sale.save! - table_update_status(sObj) if check_foc + table_update_status(sObj) update_shift elsif paid_amount.to_f > 0 #|| paid_amount != "0.0" + table_update_status(sObj) + update_shift + elsif method_status && paid_amount.to_f == 0 + table_update_status(sObj) update_shift end end diff --git a/app/models/stock_journal.rb b/app/models/stock_journal.rb index c2a12f4a..fa4bd285 100755 --- a/app/models/stock_journal.rb +++ b/app/models/stock_journal.rb @@ -8,7 +8,7 @@ class StockJournal < ApplicationRecord balance = calculate_balance(balance, item.qty) journal = StockJournal.new - journal.item_code = item.product_code + journal.item_code = item.item_instance_code journal.inventory_definition_id = inventory_definition.id journal.debit = item.qty journal.balance = balance @@ -36,12 +36,16 @@ class StockJournal < ApplicationRecord journal.save end - def self.inventory_balances(today,from,to) + def self.inventory_balances(today,from,to,from_time,to_time) 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") + if !from_time.nil? && !to_time.nil? + query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}'") + else + query = query.where("DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%Y-%m-%d') between '#{from}' and '#{to}' and DATE_FORMAT(CONVERT_TZ(stock_journals.created_at,'+00:00','+06:30'),'%H:%M') between '#{from_time}' and '#{to_time}'") + end + query = query.group("mii.item_instance_name") .order("mii.item_instance_name ASC") else query = StockJournal.select("mii.item_instance_name as item_instance_name,balance") diff --git a/app/models/survey.rb b/app/models/survey.rb index 27b6229e..840b4c1e 100644 --- a/app/models/survey.rb +++ b/app/models/survey.rb @@ -1,2 +1,17 @@ class Survey < ApplicationRecord + + def self.search(filter,from,to) + if filter.blank? + keyword = '' + else + keyword = "dining_name LIKE ?","%#{filter}%" + end + + if from.present? && to.present? + survey = Survey.where("DATE_FORMAT(created_at,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(created_at,'%d-%m-%Y') <= ?", from,to) + query = survey.where(keyword) + else + where("dining_name LIKE ?", "%#{filter}%") + end + end end diff --git a/app/models/tax_profile.rb b/app/models/tax_profile.rb index e478ecd5..a9e56fac 100755 --- a/app/models/tax_profile.rb +++ b/app/models/tax_profile.rb @@ -1,5 +1,5 @@ class TaxProfile < ApplicationRecord default_scope { order('order_by asc') } # validations - validates_presence_of :name, :rate + validates_presence_of :name, :rate, :group_type end diff --git a/app/pdf/order_item_pdf.rb b/app/pdf/order_item_pdf.rb index fabc8d11..58682d8a 100755 --- a/app/pdf/order_item_pdf.rb +++ b/app/pdf/order_item_pdf.rb @@ -110,7 +110,7 @@ class OrderItemPdf < Prawn::Document end if alt_name - if !(order_item.alt_name).empty? + if order_item.alt_name move_down 4 font("public/fonts/NotoSansCJKtc-Regular.ttf") do text "(#{order_item.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true diff --git a/app/pdf/order_item_slim_pdf.rb b/app/pdf/order_item_slim_pdf.rb index 146b585f..05add2c9 100755 --- a/app/pdf/order_item_slim_pdf.rb +++ b/app/pdf/order_item_slim_pdf.rb @@ -110,7 +110,7 @@ class OrderItemSlimPdf < Prawn::Document end # if alt_name - # if !(order_item_slim.alt_name).empty? + # if order_item_slim.alt_name # move_down 1 # font("public/fonts/NotoSansCJKtc-Regular.ttf") do # text "(#{order_item_slim.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true diff --git a/app/pdf/order_set_item_pdf.rb b/app/pdf/order_set_item_pdf.rb index 9aac0d0e..ce06081f 100755 --- a/app/pdf/order_set_item_pdf.rb +++ b/app/pdf/order_set_item_pdf.rb @@ -109,7 +109,7 @@ class OrderSetItemPdf < Prawn::Document end if alt_name - if !(order_set_item.alt_name).empty? + if order_set_item.alt_name move_down 4 font("public/fonts/NotoSansCJKtc-Regular.ttf") do text "(#{order_set_item.alt_name})", :size => self.item_font_size,:align => :left, :inline_format => true diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index fe1ee628..c0299033 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -1,111 +1,113 @@ class ReceiptBillPdf < Prawn::Document - include ActionView::Helpers::NumberHelper + 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) - self.page_width = printer_settings.page_width - self.page_height = printer_settings.page_height - self.margin = 0 - self.price_width = 60 - self.qty_width = 25 - self.total_width = 60 - self.item_width = self.page_width - ((self.qty_width + self.price_width + self.total_width)) - self.item_height = 15 - self.item_description_width = (self.page_width-5) / 2 - self.label_width = 100 + 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) + self.page_width = printer_settings.page_width + self.page_height = printer_settings.page_height + self.margin = 0 + self.price_width = 60 + self.qty_width = 25 + self.total_width = 60 + self.item_width = self.page_width - ((self.qty_width + self.price_width + self.total_width)) + self.item_height = 15 + self.item_description_width = (self.page_width-5) / 2 + self.label_width = 100 - self.description_width = 150 - self.price_num_width = 50 - self.line_move = 2 - # @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]) + self.description_width = 150 + self.price_num_width = 50 + self.line_move = 2 + # @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]) - #precision checked - if printer_settings.precision.to_i > 2 - printer_settings.precision = 2 + #precision checked + if printer_settings.precision.to_i > 2 + printer_settings.precision = 2 + end + + # 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 + + if printer_settings.delimiter + delimiter = "," + else + delimiter = "" + end + + header(shop_details) + + stroke_horizontal_rule + + cashier_info(sale_data, customer_name) + line_items(sale_items,printer_settings.precision,delimiter) + all_total(sale_data,printer_settings.precision,delimiter) + + + if member_info != nil + member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) + end + + customer(customer_name) + + #start card sale trans data + if card_data != nil + card_sale_data(card_data) + end + #end card sale trans data + + if discount_price_by_accounts.length > 0 && shop_details.show_account_info + discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) + end + + if shop_details.show_account_info + items_account(item_price_by_accounts,printer_settings.precision,delimiter) + end + + #start for individual payment + if !sale_data.equal_persons.nil? + individual_payment(sale_data, printer_settings.precision, delimiter) + end + #end for individual payment + + sign(sale_data) + + footer(printed_status) end - # 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 - - if printer_settings.delimiter - delimiter = "," - else - delimiter = "" - end - - header(shop_details) - - stroke_horizontal_rule - - cashier_info(sale_data, customer_name) - line_items(sale_items,printer_settings.precision,delimiter) - all_total(sale_data,printer_settings.precision,delimiter) - - - if member_info != nil - member_info(member_info,customer_name,rebate_amount,sale_data,printer_settings.precision,delimiter,current_balance) - end - - customer(customer_name) - - #start card sale trans data - if card_data != nil - card_sale_data(card_data) - end - #end card sale trans data - - if discount_price_by_accounts.length > 0 && shop_details.show_account_info - discount_account(discount_price_by_accounts,printer_settings.precision,delimiter) - end - - if shop_details.show_account_info - items_account(item_price_by_accounts,printer_settings.precision,delimiter) - end - - #start for individual payment - if !sale_data.equal_persons.nil? - individual_payment(sale_data, printer_settings.precision, delimiter) - end - #end for individual payment - - sign(sale_data) - - footer(printed_status) - end - - def header (shop_details) - text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center - move_down line_move - text "#{shop_details.address}", :size => self.item_font_size,:align => :center - # move_down self.item_height - move_down line_move - text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center - move_down line_move - - stroke_horizontal_rule - end - - def cashier_info(sale_data, customer_name) + def header (shop_details) + text "#{shop_details.name}", :left_margin => -10, :size => self.header_font_size,:align => :center move_down line_move + text "#{shop_details.address}", :size => self.item_font_size,:align => :center + # move_down self.item_height + move_down line_move + text "#{shop_details.phone_no}", :size => self.item_font_size,:align => :center + move_down line_move + + stroke_horizontal_rule + end + + def cashier_info(sale_data, customer_name) + move_down line_move + # move_down 2 y_position = cursor bounding_box([0,y_position], :width =>self.description_width + self.price_num_width, :height => self.item_height) do @@ -117,17 +119,10 @@ class ReceiptBillPdf < Prawn::Document 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 - if sale_data.bookings[0].dining_facility_id.to_i > 0 - bounding_box([0,y_position], :width => self.label_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 => :left - end - end - - bounding_box([self.label_width, y_position], :width =>self.label_width, :height => self.item_height) do + bounding_box([0, y_position], :width =>self.label_width, :height => self.item_height) do text "W: #{sale_data.requested_by}" , :size => self.item_font_size, :align => :left end bounding_box([self.label_width - 2,y_position], :width =>self.label_width, :height => self.item_height) do @@ -141,12 +136,11 @@ class ReceiptBillPdf < Prawn::Document else 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 text "Date : #{ time }",:size => self.item_font_size,:align => :left end - # bounding_box([self.item_description_width,y_position], :width =>self.label_width+5) do # text "(#{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') } # - #{ sale_data.bookings[0].checkin_at.utc.getlocal.strftime('%I:%M %p') })" , @@ -155,7 +149,7 @@ class ReceiptBillPdf < Prawn::Document move_down line_move stroke_horizontal_rule - end + end def line_items(sale_items,precision,delimiter) if precision.to_i > 0 @@ -250,7 +244,6 @@ class ReceiptBillPdf < Prawn::Document end def all_total(sale_data,precision,delimiter) - move_down line_move item_name_width = self.item_width y_position = cursor @@ -316,8 +309,7 @@ class ReceiptBillPdf < Prawn::Document end move_down line_move - sale_payment(sale_data,precision,delimiter) - + sale_payment(sale_data,precision,delimiter) end def sale_payment(sale_data,precision,delimiter) @@ -494,8 +486,8 @@ class ReceiptBillPdf < Prawn::Document end #individual payment per person - def individual_payment(sale_data, precision, delimiter) - per_person = sale_data.grand_total.to_i / sale_data.equal_persons.to_i + def individual_payment(sale_data, survey, precision, delimiter) + per_person = sale_data.grand_total.to_f / survey.total_customer.to_i stroke_horizontal_rule move_down line_move y_position = cursor @@ -548,8 +540,7 @@ class ReceiptBillPdf < Prawn::Document text "Acknowledged By" , :size => self.item_font_size,:align => :center end end - - + end def footer(printed_status) diff --git a/app/views/home/dashboard.html.erb b/app/views/home/dashboard.html.erb index aee947c7..865202b0 100755 --- a/app/views/home/dashboard.html.erb +++ b/app/views/home/dashboard.html.erb @@ -68,16 +68,48 @@
-
+ <% + if !@from.nil? + from_date = DateTime.parse(@from).utc.getlocal.strftime("%d-%m-%Y") + else + from_date = Time.now.utc.getlocal.strftime('%d-%m-%Y') + end + if !@to.nil? + to_date = DateTime.parse(@to).utc.getlocal.strftime("%d-%m-%Y") + else + to_date = Time.now.utc.getlocal.strftime('%d-%m-%Y') + end + if !@from_time.nil? + from_time = @from_time + else + from_time = '' + end + if !@to_time.nil? + to_time = @to_time + else + to_time = '' + end + %> +
- +
-
+
- +
+
+ + + +
+
+ + + +

@@ -340,21 +372,53 @@ $('.btn_generate').on('click',function(){ var from = $("#from").val(); var to = $("#to").val(); + var from_time = $("#from_time").val(); + var to_time = $("#to_time").val(); + + if(check(from,to,from_time,to_time)){ + var params = '?'; + if((from!='' && to!='') && (from_time!='' && to_time!='')){ + params += 'from='+from+'&to='+to+'&from_time='+from_time+'&to_time='+to_time; + }else{ + params += 'from='+from+'&to='+to; + } + window.location.href = '/dashboard'+params; + } + }); + + function check(from,to,from_time,to_time){ + var status = true; if((from=='') && (to=='')){ + status = false; $('#fromErr').html("can't be blank"); $('#toErr').html("can't be blank"); }else if((from!='') && (to=='')){ + status = false; $('#fromErr').html(""); $('#toErr').html("can't be blank"); }else if((from=='') && (to!='')){ + status = false; $('#fromErr').html("can't be blank"); $('#toErr').html(""); }else{ + status = true; $('#fromErr').html(""); $('#toErr').html(""); } - if((from!='') && (to!='')){ - window.location.href = '/dashboard?from='+from+'&to='+to; + + if(((from_time=='') && (to_time=='')) || ((from_time!='') && (to_time!=''))){ + status = true; + $('#from_timeErr').html(""); + $('#to_timeErr').html(""); + }else if((from_time!='') && (to_time=='')){ + status = false; + $('#from_timeErr').html(""); + $('#to_timeErr').html("can't be blank"); + }else if((from_time=='') && (to_time!='')){ + status = false; + $('#from_timeErr').html("can't be blank"); + $('#to_timeErr').html(""); } - }); + return status; + } \ No newline at end of file diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb old mode 100755 new mode 100644 index e3d08824..63067ec0 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -109,6 +109,11 @@ <%= (t :shiftsale) %> <% end %> + <% if can? :menage, Survey %> +
  • + <%= t("views.right_panel.detail.survey") %> +
  • + <% end %> <% if can? :index, :dailysale %> diff --git a/app/views/oqs/edit/index.html.erb b/app/views/oqs/edit/index.html.erb old mode 100755 new mode 100644 index 775b214d..27595303 --- a/app/views/oqs/edit/index.html.erb +++ b/app/views/oqs/edit/index.html.erb @@ -112,6 +112,11 @@ $(document).ready(function(){ var remarks = $("textarea[name='remarks']").val(); var order_items_id = $(this).attr('data-id'); var params = { 'order_items_id': order_items_id, 'qty_weight': qty_weight, 'remarks': remarks } + var booking_id = ''; + <% if !@booking.nil? %> + booking_id = '<%= @booking.booking_id %>'; + <% end %> + $.ajax({ type: 'POST', url: '/oqs/' + order_items_id, @@ -121,6 +126,8 @@ $(document).ready(function(){ <% if !@link_type.nil? %> <% if @link_type == 'oqs' %> window.location.href = '/oqs'; + <% elsif @link_type == 'pending' %> + window.location.href = '/origami/quick_service/pending_order/'+booking_id; <% else %> <% if !@dining_type.nil? %> <% if @dining_type == 'Table' %> @@ -140,9 +147,15 @@ $(document).ready(function(){ }); $('#back').on('click', function () { + var booking_id = ''; + <% if !@booking.nil? %> + booking_id = '<%= @booking.booking_id %>'; + <% end %> <% if !@link_type.nil? %> <% if @link_type == 'oqs' %> window.location.href = '/oqs'; + <% elsif @link_type == 'pending' %> + window.location.href = '/origami/quick_service/pending_order/'+booking_id; <% else %> <% if !@dining_type.nil? %> <% if @dining_type == 'Table' %> diff --git a/app/views/origami/addorders/detail.html.erb b/app/views/origami/addorders/detail.html.erb index 6c580f40..607f4c0e 100755 --- a/app/views/origami/addorders/detail.html.erb +++ b/app/views/origami/addorders/detail.html.erb @@ -35,6 +35,7 @@ <%end%> +
    -
    -
    +
    +
    -
    +
    @@ -375,7 +377,7 @@ @@ -715,6 +714,7 @@ $("#first_bill").on('click', function () { var sale_id = $('#sale_id').val(); var ajax_url = "/origami/sale/" + sale_id + "/first_bill"; + var server_mode = $.ajax({ type: "GET", @@ -723,17 +723,40 @@ receipt_no = ($("#receipt_no").html()).trim(); if((receipt_no!=undefined) && (receipt_no!="")) createReceiptNoInFirstBillData(receipt_no,""); - + + // For Server Print - from jade + if ($("#server_mode").val() == "cloud") { + code2lab.printFile(result.filepath.substr(6), result.printer_url); + } + + // console.log(result); + // code2lab.printBill(result.filepath, result.printer_model, result.printer_url); location.reload(); } - }); + }); }); + // click select option icon for add + $(document).on('click', '.payment_btn', function(event){ + active = $(this).hasClass('selected-payment'); + value = $(this).data('value'); + type = $(this).data('type'); + group = $(this).data('group'); + payments = $(".payment_btn"); + + if (active) { + $(this).removeClass('selected-payment'); + }else{ + $(this).addClass('selected-payment'); + } + }); //End selecct attribute buttom + $(".choose_payment").on('click', function () { $( "#loading_wrapper").show(); var sale_id = $('#sale_id').val(); - type = $('.payment_method').val(); + // type = $('.payment_method').val(); + type = get_selected_attributes('selected-payment'); if(parseInt(jQuery.inArray("Credit", type)) == -1){ if (parseInt(jQuery.inArray("MPU", type)) != -1 || parseInt(jQuery.inArray("VISA", type)) != -1 || parseInt(jQuery.inArray("JCB", type)) != -1 || parseInt(jQuery.inArray("Master", type)) != -1 || parseInt(jQuery.inArray("UNIONPAY", type)) != -1 || parseInt(jQuery.inArray("Redeem", type)) != -1) { calculate_member_discount(sale_id,"Card"); @@ -751,7 +774,11 @@ receipt_no = ($("#receipt_no").html()).trim(); if((receipt_no!=undefined) && (receipt_no!="")) createReceiptNoInFirstBillData(receipt_no,type); - location.reload(); + // For Server Print - from jade + if ($("#server_mode").val() == "cloud") { + code2lab.printFile(result.filepath.substr(6), result.printer_url); + } + location.reload(); } }); }); @@ -801,7 +828,7 @@ //split bill process $('#split_bills').click(function(){ var dining_id = "<%= @dining.id %>"; - window.location.href = '/origami/table/' + dining_id + "/split_bills"; + window.location.href = '/origami/table/' + dining_id + "/" + cashier_type +"/split_bills"; }); $('#move').on('click', function () { @@ -905,15 +932,19 @@ }, function (isConfirm) { if (isConfirm) { var sale_id = "<%= @obj_sale.sale_id rescue "" %>" - var ajax_url = "/origami/sale/" + sale_id + '/void'; + var ajax_url = "/origami/sale/" + sale_id + '/cashier/void'; var remark = $("#remark").val(); $.ajax({ type: 'POST', url: ajax_url, data: "remark="+ remark + "&sale_id=" + sale_id, - success: function () { - window.location.href = '/origami/'; + success: function (result) { + // For Server Print - from jade + if ($("#server_mode").val() == "cloud") { + code2lab.printFile(result.filepath.substr(6), result.printer_url); + } + window.location.href = '/origami/'; } }); } @@ -971,4 +1002,16 @@ window.location.href = '/oqs/'+ assigned_order_item_id + "/edit/"+dining_id; } }); + + // Get Selected Class + function get_selected_attributes(selected_class) { + var item_row = $('.'+selected_class); + var attribute_arr = []; + $(item_row).each(function(i){ + value = $(item_row[i]).attr('data-value'); + str = value; + attribute_arr.push(str); + }); + return attribute_arr; + } diff --git a/app/views/origami/junction_pay/create.json.jbuilder b/app/views/origami/junction_pay/create.json.jbuilder new file mode 100755 index 00000000..9767a7d8 --- /dev/null +++ b/app/views/origami/junction_pay/create.json.jbuilder @@ -0,0 +1,5 @@ +if(@status) + json.status @status +else + json.status false +end diff --git a/app/views/origami/junction_pay/index.html.erb b/app/views/origami/junction_pay/index.html.erb new file mode 100755 index 00000000..cdbdc47d --- /dev/null +++ b/app/views/origami/junction_pay/index.html.erb @@ -0,0 +1,300 @@ +
    + + +
    +
    + + + +
    +
    +
    +
    + + +
    +
    +
    + +
    +
    + + <%@can_junction_pay = @can_junction_pay +@rounding_adj%> + +
    +
    +
    + <% if @jcbcount != 0 %> +
    +
    + + +
    +
    +
    + <% end %> +
    +
    + + +
    +
    +
    +
    +
    +
    + +
    0.0
    +
    +
    +
    +
    +
    +
    + +
    +
    +
    +
    +
    +
    1
    +
    2
    +
    3
    +
    +
    +
    4
    +
    5
    +
    6
    +
    +
    +
    7
    +
    8
    +
    9
    +
    +
    +
    0
    +
    .
    +
    00
    +
    +
    +
    Nett
    +
    Del
    +
    Clr
    +
    +
    +
    +
    +
    1000
    +
    3000
    +
    +
    +
    5000
    +
    10000
    +
    +
    +
    Pay
    +
    +
    +
    +
    +
    + +
    + +
    +
    +
    + diff --git a/app/views/origami/other_charges/index.html.erb b/app/views/origami/other_charges/index.html.erb index 6a9e1bb6..1423d1a6 100755 --- a/app/views/origami/other_charges/index.html.erb +++ b/app/views/origami/other_charges/index.html.erb @@ -309,7 +309,7 @@ var cashier_type = "<%= @cashier_type %>"; var other_charges_items = JSON.stringify(get_other_item_rows()); var ajax_url = "/origami/" + sale_id + "/other_charges"; - var params = { 'sale_id': sale_id, 'sub_total': sub_total, 'other_charges_items': other_charges_items }; + var params = { 'cashier_type' : cashier_type,'sale_id': sale_id, 'sub_total': sub_total, 'other_charges_items': other_charges_items }; $.ajax({ type: "POST", diff --git a/app/views/origami/payments/show.html.erb b/app/views/origami/payments/show.html.erb index acd97d0b..8226c75a 100755 --- a/app/views/origami/payments/show.html.erb +++ b/app/views/origami/payments/show.html.erb @@ -100,10 +100,10 @@ @@ -265,6 +265,20 @@
    <%= number_with_precision(0, precision: precision.to_i ) %>
    <% end %> + + <% if @junctionpaycount != 0.0 %> +
    +
    +
    JUNCTION PAY
    +
    <%= number_with_precision(@junctionpaycount, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    +
    + <% else %> + + <% end %>
    Balance
    <%= number_with_precision(@sale_data.grand_total, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i ) %>
    @@ -406,11 +420,11 @@
    + - + <% end%> <% end%> @@ -211,7 +213,7 @@ $(document).ready(function(){ swal("Information!", result.error_message); } else { - window.location.href = '../pending_order/'+ result.data; + window.location.href = '/origami/quick_service/pending_order'; } } }); @@ -290,5 +292,13 @@ $(document).ready(function(){ window.location.href = linkURL; }); } + + /*edit order in oqs*/ + $('.edit_order').on('click',function(){ + var assigned_order_item_id = $(this).attr('data-id'); + if((assigned_order_item_id!=undefined) && (assigned_order_item_id!='')){ + window.location.href = '/oqs/'+ assigned_order_item_id + "/edit/pending"; + } + }); }); diff --git a/app/views/origami/rooms/show.html.erb b/app/views/origami/rooms/show.html.erb index d98a3fe2..424690ff 100755 --- a/app/views/origami/rooms/show.html.erb +++ b/app/views/origami/rooms/show.html.erb @@ -465,15 +465,15 @@ <% end %> <% if current_login_employee.role != "waiter" %> - <% if ENV["SERVER_MODE"] == "cloud" %> + <%if @membership.discount && @obj_sale.customer.membership_id %> <%else%> <%end%> - <%end%> + <% end %> @@ -489,16 +489,13 @@ \ No newline at end of file diff --git a/app/views/settings/menus/index.html.erb b/app/views/settings/menus/index.html.erb index 99b678ef..5fafa5db 100755 --- a/app/views/settings/menus/index.html.erb +++ b/app/views/settings/menus/index.html.erb @@ -24,7 +24,16 @@
    +
    + <%= form_tag import_settings_menus_path,class:"col-md-", multipart:true do%> + <%=file_field_tag :file, :class => "img-thumbnail col-md-7" %> + <%=submit_tag "Import",:class => 'btn btn-primary btn-lg waves-effect' %> + <%end%> +
    <%= link_to t("views.btn.new"),new_settings_menu_path,:class => 'btn btn-primary btn-lg float-right waves-effect"' %> + + <%= link_to "Export", settings_menus_path(format: "xlsx"),:class => 'btn btn-info btn-lg waves-effect float-right m-r-10' %> +
    Tax (<% @i = 0 @account_arr.each do |ct| %> - <%=ct.name%> - <% if @account_arr.count != @i+1%> - + <% @i =+1 %> - <%end%> + <%=ct.name%> + <% if @account_arr.count != @i+1%> + + <% @i =+1 %> + <%end%> <%end %>) <%= number_with_precision(@sale_data.total_tax, precision: precision.to_i ) rescue number_with_precision(0, precision: precision.to_i )%>
    <%= order_item.item_name %> <%= order_item.qty %><%= order_item.price %><%= total %>
    diff --git a/app/views/settings/menus/index.xlsx.axlsx b/app/views/settings/menus/index.xlsx.axlsx new file mode 100644 index 00000000..b148931a --- /dev/null +++ b/app/views/settings/menus/index.xlsx.axlsx @@ -0,0 +1,86 @@ +wb = xlsx_package.workbook +wb.styles do |s| + time_format = wb.styles.add_style :format_code => 'hh:mm:ss' + + wrap_text = s.add_style :sz => 11, + :alignment => { :horizontal => :left,:vertical => :center , + :wrap_text => true} + header_text = s.add_style :fg_color=> "FFFFFF", + :b => true, + :bg_color => "004586", + :sz => 12, + :border => { :style => :thin, :color => "00" }, + :alignment => { :horizontal => :left, + :vertical => :center , + :header_text => true} + wb.add_worksheet(name: "Account") do |sheet| + sheet.add_row %w(id title account_type discount point bonus rebate), :style=>header_text + Account.all.each do |acc| + sheet.add_row [acc.id, acc.title,acc.account_type,acc.discount,acc.point,acc.bonus,acc.rebate], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Item Set") do |sheet| + sheet.add_row %w(id name alt_name min_selectable_qty max_selectable_qty), :style=>header_text + ItemSet.all.each do |set| + sheet.add_row [set.id,set.name, set.alt_name, set.min_selectable_qty, set.max_selectable_qty], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu Item Options") do |sheet| + sheet.add_row %w(id option_type name value), :style=>header_text + MenuItemOption.all.each do |option| + sheet.add_row [option.id, option.option_type, option.name, option.value], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu Item Attributes") do |sheet| + sheet.add_row %w(id attribute_type name value), :style=>header_text + MenuItemAttribute.all.each do |attr| + sheet.add_row [attr.id, attr.attribute_type,attr.name,attr.value], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu") do |sheet| + sheet.add_row %w( id name is_active valid_days valid_time_from valid_time_to created_by ), :style=>header_text + @settings_menus.each do |menu| + sheet.add_row [ menu.id, menu.name, menu.is_active, menu.valid_days, menu.valid_time_from,menu.valid_time_to, menu.created_by], :style=>[wrap_text,time_format] + end + end + + wb.add_worksheet(name: "Menu Category") do |sheet| + sheet.add_row %w(id menu_id code name alt_name order_by created_by menu_category_id is_available), :style=>header_text + MenuCategory.all.each do |mc| + sheet.add_row [mc.id, mc.menu_id, mc.code, mc.name, mc.alt_name, mc.order_by, mc.created_by, mc.menu_category_id, mc.is_available], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu Item") do |sheet| + sheet.add_row %w(id item_code name alt_name image_path description information unit type menu_category_id item_attributes item_options account_id min_qty taxable is_sub_item is_available created_by), :style=>header_text + MenuItem.all.each do |mi| + sheet.add_row [mi.id,mi.item_code, mi.name, mi.alt_name, mi.image_path, mi.description, mi.information, mi.unit, mi.type, mi.menu_category_id, mi.item_attributes, mi.item_options, mi.account_id, mi.min_qty, mi.taxable, mi.is_sub_item, mi.is_available, mi.created_by], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu Item Instance") do |sheet| + sheet.add_row %w(id menu_item_id item_instance_code item_instance_name item_attributes price is_on_promotion promotion_price is_available is_default), :style=>header_text + MenuItemInstance.all.each do |mii| + sheet.add_row [mii.id, mii.menu_item_id, mii.item_instance_code, mii.item_instance_name, mii.item_attributes, mii.price, mii.is_on_promotion, mii.promotion_price, mii.is_available, mii.is_default], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu Instance Item Set") do |sheet| + sheet.add_row %w(id item_set_id menu_item_instance_id), :style=>header_text + MenuInstanceItemSet.all.each do |miis| + sheet.add_row [miis.id ,miis.item_set_id, miis.menu_item_instance_id], :style=>wrap_text + end + end + + wb.add_worksheet(name: "Menu Item Set") do |sheet| + sheet.add_row %w(id item_set_id menu_item_id), :style=>header_text + MenuItemSet.all.each do |mis| + sheet.add_row [mis.id,mis.item_set_id, mis.menu_item_id], :style=>wrap_text + end + end + +end diff --git a/app/views/settings/tax_profiles/_form.html.erb b/app/views/settings/tax_profiles/_form.html.erb index bd397920..5ffd29aa 100755 --- a/app/views/settings/tax_profiles/_form.html.erb +++ b/app/views/settings/tax_profiles/_form.html.erb @@ -8,14 +8,16 @@ <%= f.error_notification %>
    - <%= f.input :name %> + <%= f.input :group_type, :collection => Lookup.collection_of("tax_profiles"),:input_html=>{:class=>"col-md-10"},:required=>true %> + <%= f.input :name, :input_html=>{:onchange=>"checkDuplicate(this.value);"} %> + <%= f.input :rate %> <%= f.input :inclusive %> <%= f.input :order_by %>
    - <%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect' %> + <%= f.submit "Submit",:class => 'btn btn-primary btn-lg waves-effect btn_submit' %>
    <% end %> @@ -45,5 +47,25 @@ - + diff --git a/app/views/settings/tax_profiles/index.html.erb b/app/views/settings/tax_profiles/index.html.erb index fdfc0895..e1e63c06 100755 --- a/app/views/settings/tax_profiles/index.html.erb +++ b/app/views/settings/tax_profiles/index.html.erb @@ -17,6 +17,7 @@
    + @@ -29,6 +30,7 @@ <% @settings_tax_profiles.each do |settings_tax_profile| %> + diff --git a/app/views/settings/tax_profiles/show.html.erb b/app/views/settings/tax_profiles/show.html.erb index 77a503f2..b405066f 100755 --- a/app/views/settings/tax_profiles/show.html.erb +++ b/app/views/settings/tax_profiles/show.html.erb @@ -15,6 +15,11 @@

    <%= t("en.tax_profile") %>

    <%= t("views.right_panel.detail.group_type") %> <%= t("views.right_panel.detail.name") %> <%= t("views.right_panel.detail.rate") %> <%= t("views.right_panel.detail.inclusive") %>
    <%= settings_tax_profile.group_type %> <%= settings_tax_profile.name %> <%= settings_tax_profile.rate %> <%= settings_tax_profile.inclusive %>
    + + + + + diff --git a/app/views/transactions/sales/index.html.erb b/app/views/transactions/sales/index.html.erb old mode 100755 new mode 100644 index 172320df..26fbbcc5 --- a/app/views/transactions/sales/index.html.erb +++ b/app/views/transactions/sales/index.html.erb @@ -17,17 +17,41 @@ + @@ -67,7 +92,16 @@ <% if @sales != 0 %> <% @sales.each do |sale| %> - + @@ -75,11 +109,20 @@ + <% end %> <% else %> - + <% end %>
    <%= t("views.right_panel.detail.group_type") %>:<%= @settings_tax_profile.group_type %>
    <%= t("views.right_panel.detail.name") %>: <%= @settings_tax_profile.name %> <%= form_tag transactions_sales_path, :method => :get do %>
    -
    +
    - +
    -
    - - + +
    + +
    -
    + +
    + + +
    +
    - + +
    + +
    + +
    @@ -59,6 +83,7 @@
    <%= t("views.right_panel.detail.grand_total") %> <%= t :cashier %> <%= t("views.right_panel.detail.sales_status") %><%= t("views.right_panel.detail.remark") %> <%= t("views.right_panel.detail.receipt_date") %>
    <%= link_to sale.sale_id, transactions_sale_path(sale) %> + <% if !@sale_item_audits.nil? %> + <% @sale_item_audits.each do |audit| %> + <%if audit.include?(sale.sale_id) %> + * + <% end %> + <% end %> + <% end %> + <%= link_to sale.sale_id, transactions_sale_path(sale) %> + <%= sale.receipt_no %> <%= sale.total_discount %> <%= sale.total_tax %><%= sale.grand_total rescue '-' %> <%= sale.cashier_name rescue '-' %> <%= sale.sale_status %> + <% if !@sale_audits.nil? %> + <% @sale_audits.each do |audit| %> + <%if audit.include?(sale.sale_id) %> + <%= audit[sale.sale_id] %> + <% end %> + <% end %> + <% end %> + <%= sale.receipt_date.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") %>

    There is no data for search....

    There is no data for search....

    @@ -97,9 +140,107 @@ diff --git a/app/views/transactions/sales/show.html.erb b/app/views/transactions/sales/show.html.erb index bd6ce960..9cab82a5 100755 --- a/app/views/transactions/sales/show.html.erb +++ b/app/views/transactions/sales/show.html.erb @@ -52,7 +52,7 @@ <%= @sale.receipt_no %> <%= @sale.cashier_name rescue '-' %> <%= @sale.sale_status %> - <%= @sale.requested_at.strftime("%m-%d-%Y %H:%M %p") %> + <%= @sale.requested_at.strftime("%m-%d-%Y %H:%M %p") %> <%= t :sale %> <%= t("views.right_panel.detail.item_txt") %> <%= t("views.right_panel.detail.name_txt2") %> @@ -60,6 +60,7 @@ <%= t("views.right_panel.detail.unit_price") %> <%= t("views.right_panel.detail.total_price") %> <%= t("views.right_panel.detail.created_at") %> + <%= t("views.right_panel.detail.remark") %> <% @sale.sale_items.each do |s| %> @@ -69,42 +70,43 @@ <%= number_with_precision(s.price, :precision => 2, :delimiter => ',') rescue ' '%> <%= number_with_precision(s.qty * s.price, :precision => 2, :delimiter => ',') rescue ' '%> <%=l s.created_at.utc.getlocal , :format => :short rescue ' ' %> + <%=s.remark rescue ' '%> <% end %> <%= t("views.right_panel.detail.total") %> - <%= number_with_precision(@sale.total_amount, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_with_precision(@sale.total_amount, :precision => 2, :delimiter => ',') rescue ' '%> <%= t("views.right_panel.detail.discount") %> - <%= number_with_precision(@sale.total_discount, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_with_precision(@sale.total_discount, :precision => 2, :delimiter => ',') rescue ' '%> <% @sale.sale_taxes.each do |r|%> <%= r.tax_name %> - <%= number_with_precision(r.tax_payable_amount, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_with_precision(r.tax_payable_amount, :precision => 2, :delimiter => ',') rescue ' '%> <% end %> <%= t("views.right_panel.detail.grand_total") %> - <%= number_with_precision(@sale.grand_total, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_with_precision(@sale.grand_total, :precision => 2, :delimiter => ',') rescue ' '%>   <%= t("views.right_panel.detail.total_pay_amount") %> - <%= number_with_precision(@sale.amount_received, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_with_precision(@sale.amount_received, :precision => 2, :delimiter => ',') rescue ' '%> <% @sale_receivables.each do |r|%> <%= r.payment_method.capitalize rescue ' '%> Payment - <%= number_with_precision(r.payment_amount, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_with_precision(r.payment_amount, :precision => 2, :delimiter => ',') rescue ' '%> @@ -114,7 +116,7 @@ <%= t("views.right_panel.detail.change") %> - <%= number_with_precision(@sale.amount_changed, :precision => 2, :delimiter => ',') rescue ' '%> + <%= number_with_precision(@sale.amount_changed, :precision => 2, :delimiter => ',') rescue ' '%> @@ -258,9 +260,3 @@
    - - - - - - diff --git a/app/views/transactions/surveys/index.html.erb b/app/views/transactions/surveys/index.html.erb new file mode 100644 index 00000000..66defdc0 --- /dev/null +++ b/app/views/transactions/surveys/index.html.erb @@ -0,0 +1,113 @@ + +
    +
    +
    + <%= form_tag transactions_surveys_path, :method => :get do %> +
    +
    + + +
    + +
    + + +
    + +
    + + +
    + +
    + +
    +
    +
    + <% end %> +
    +
    + + + + + + + + + + + + + + + <% total_child = 0 %> + <% total_adult = 0 %> + <% total_male = 0 %> + <% total_female = 0 %> + <% total_local = 0 %> + <% total_customer = 0 %> + <% if !@surveys.nil? %> + <% @surveys.each do |survey| %> + <% total_child = total_child.to_i + survey.child.to_i %> + <% total_adult = total_adult.to_i + survey.adult.to_i %> + <% total_male = total_male.to_i + survey.male.to_i %> + <% total_female = total_female.to_i + survey.female.to_i %> + <% total_local = total_local.to_i + survey.local.to_i %> + <% total_customer = total_customer.to_i + survey.total_customer.to_i %> + + + + + + + + + + + + + <% end %> + <% end %> + + + + + + + + + + +
    <%= t("views.right_panel.detail.dining") %><%= t("views.right_panel.detail.receipt_no") %><%= t("views.right_panel.detail.created_by") %><%= t("views.right_panel.detail.child") %><%= t("views.right_panel.detail.adult") %><%= t("views.right_panel.detail.male") %><%= t("views.right_panel.detail.female") %><%= t("views.right_panel.detail.total") %> <%= t :customer %> + <%= t("views.right_panel.detail.local") %><%= t("views.right_panel.detail.foreigner") %>
    <%= survey.dining_name rescue ' '%><%= survey.receipt_no rescue '-'%><%= survey.created_by rescue ' '%><%= survey.child rescue ' '%><%= survey.adult rescue ' '%><%= survey.male rescue ' '%><%= survey.female rescue ' '%><%= survey.total_customer rescue ' '%><%= survey.local rescue ' '%> + <% if !survey.foreigner.nil? %> + <% JSON.parse(survey.foreigner).each do |foreign| %> + <% foreigner_lists = foreign.split(",") %> + <% if !foreigner_lists.empty? %> + <% foreigner_lists.each do |fgn| %> + <% if !fgn.scan(/\D/).empty? %> + <%= fgn %> :<% end %> <%= fgn.to_i unless fgn.match(/[^[:digit:]]+/) %>
    + <% end %> + <% end %> + <% end %> + <% end %> +
    <%= t("views.right_panel.detail.total") %><%= total_child %><%= total_adult %><%= total_male %><%= total_female %><%= total_customer %><%= total_local %>
    +
    + <%if !@orders.nil?%> + <%= paginate @surveys %> + <%end%> +
    +
    +
    + +
    +
    diff --git a/config/.database.yml.swp b/config/.database.yml.swp deleted file mode 100755 index 09f1aac2..00000000 Binary files a/config/.database.yml.swp and /dev/null differ diff --git a/config/application.rb b/config/application.rb index f4cbac01..0e75d195 100755 --- a/config/application.rb +++ b/config/application.rb @@ -2,6 +2,7 @@ require_relative 'boot' require 'csv' require 'rails/all' +# require 'iconv' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. @@ -20,5 +21,7 @@ module SXRestaurants config.active_record.time_zone_aware_types = [:datetime, :time] config.active_job.queue_adapter = :sidekiq config.time_zone = 'Asia/Rangoon' + + end end diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index 3859c754..3e0fb279 100755 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -3,3 +3,4 @@ # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf Mime::Type.register 'application/vnd.ms-excel', :xls +Mime::Type.register "application/xlsx", :xlsx diff --git a/config/locales/en.yml b/config/locales/en.yml old mode 100755 new mode 100644 index c66d4cc3..84a7b03a --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -72,6 +72,8 @@ en: payment: "Payment" backend: "Backend" date_time: "DateTime" + dine_in_order: "Dine In Order" + quick_service: "Quick Service" views: btn: @@ -450,6 +452,11 @@ en: additional_parameter: "Additional parameter" lookup: "Lookup" product_sale_report: "Product Sale" + dining: "Dining" + child: "Child" + adult: "Adult" + foreigner: "Foreigner" + local: "Local" code_txt: "code " charge_txt: "charge" diff --git a/config/locales/mm.yml b/config/locales/mm.yml old mode 100755 new mode 100644 index 8ede4a79..f18136c4 --- a/config/locales/mm.yml +++ b/config/locales/mm.yml @@ -65,8 +65,10 @@ mm: sale_audits: "အရောင်းပြင်ဆင်ခြင်းများ" bottom: "အရောင်းအနဲဆုံး" payment: "ငွေပေးချေမှု" - backend: "Backend" - date_time: "DateTime" + backend: "နောက်ကွယ်" + date_time: "ရက်စွဲအချိန်" + dine_in_order: "Dine In Order" + quick_service: "Quick Service" views: btn: @@ -444,7 +446,12 @@ mm: additional_parameter: "ထပ်ဖြည့်အကြောင်းအရာ" survey: "ခြုံငုံလေ့လာခြင်း" lookup: "သတ်မှတ်ချက်များ" - product_sale_report: "Product Sale" + product_sale_report: "ကုန်ပစ္စည်းရောင်းရမှုအစီရင်ခံစာ" + dining: "ဆိုင်စား" + child: "ကလေး" + adult: "လူကြီး" + foreigner: "နိုင်ငံခြားသား" + local: "နိုင်ငံသား" code_txt: "ကုတ်ဒ် " charge_txt: "ကောက်ခံသည်" diff --git a/config/puma.rb.backup b/config/puma.rb.backup new file mode 100755 index 00000000..c8e0145e --- /dev/null +++ b/config/puma.rb.backup @@ -0,0 +1,48 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum, this matches the default thread size of Active Record. +# +threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 }.to_i +threads threads_count, threads_count + +# Specifies the `port` that Puma will listen on to receive requests, default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked webserver processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. If you use this option +# you need to make sure to reconnect any threads in the `on_worker_boot` +# block. +# +# preload_app! + +# The code in the `on_worker_boot` will be called if you are using +# clustered mode by specifying a number of `workers`. After each worker +# process is booted this block will be run, if you are using `preload_app!` +# option you will want to use this block to reconnect to any threads +# or connections that may have been created at application boot, Ruby +# cannot share connections between processes. +# +# on_worker_boot do +# ActiveRecord::Base.establish_connection if defined?(ActiveRecord) +# end + +# Allow puma to be restarted by `rails restart` command. + +plugin :tmp_restart diff --git a/config/routes.rb b/config/routes.rb index 88def9dc..4293a341 100755 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,6 +55,7 @@ scope "(:locale)", locale: /en|mm/ do post "bill" => "bill#create" end get 'view_orders' => "orders#view_orders" + post "update_order_item" => "orders#update" #Current active bookings resources :bookings, only: [:index, :show, :create, :update] @@ -95,9 +96,6 @@ scope "(:locale)", locale: /en|mm/ do get "quick_service/modify_order/:sale_id" => "quick_service#modify_order" post 'quick_service/update_modify_order' => "quick_service#update_modify_order", :defaults => { :format => 'json' } - resources :second_display - - post '/customer_view' => "second_display#customer_view",:as => "customer_view", :defaults => { :format => 'json' } resources :cash_ins, only: [:new, :create] resources :cash_outs, only: [:new, :create] @@ -140,7 +138,7 @@ scope "(:locale)", locale: /en|mm/ do # Discount get "/:id/:type/discount" => "discounts#index" post "/:id/discount" => "discounts#create" - get "/:id/remove_all_discount" => "discounts#remove_all_discount" + get "/:id/:type/remove_all_discount" => "discounts#remove_all_discount" post "/:id/remove_discount_items" => "discounts#remove_discount_items" # Discount for Member @@ -170,7 +168,7 @@ scope "(:locale)", locale: /en|mm/ do get 'sale/:sale_id/:type/payment' => 'payments#show' post 'sale/:sale_id/:type/payment/print' => 'payments#print' #route for print receipt - post 'payment/foc' => 'payments#foc', :defaults => {:format => 'json'} + post 'payment/:type/foc' => 'payments#foc', :defaults => {:format => 'json'} post 'payment/cash' => 'payments#create' post 'payment/mpu' => "mpu#create" post 'payment/jcb' => "jcb#create" @@ -192,7 +190,7 @@ scope "(:locale)", locale: /en|mm/ do get 'sale/:sale_id/:type/payment/others_payment/Voucher' => "voucher#index" #---------Void --------------# - post 'sale/:sale_id/void' => 'void#overall_void' + post 'sale/:sale_id/:type/void' => 'void#overall_void' #---------Multiple Invoices --------------# get 'table/:table_id/table_invoices' => "table_invoices#index", :as => "table_invoice_index" @@ -238,12 +236,15 @@ scope "(:locale)", locale: /en|mm/ do post "bank_integration/sale_trans", to: "bank_integration#sale_trans", as:"sale_trans" #split bill - get '/table/:dining_id/split_bills' => 'split_bill#index' - get '/room/:dining_id/split_bills' => 'split_bill#index' + get '/table/:dining_id/:type/split_bills' => 'split_bill#index' + get '/room/:dining_id/:type/split_bills' => 'split_bill#index' post '/split_bills', to: 'split_bill#create', as:"order_item_split_bills" post '/split_bills/equal_person', to: 'split_bill#update_sale' + resources :second_display #second display routes + + post '/customer_view' => "second_display#customer_view",:as => "customer_view", :defaults => { :format => 'json' } end #--------- Waiter/Ordering Station ------------# @@ -289,15 +290,14 @@ scope "(:locale)", locale: /en|mm/ do #--------- System Settings ------------# namespace :settings do - resources :shops do - resources :display_images - end - + resources :shops #employees resources :employees #menu resources :menus do - #menu_categories + collection do + post :import + end resources :menu_categories, only: [:new, :create, :edit, :delete] end @@ -383,6 +383,7 @@ scope "(:locale)", locale: /en|mm/ do resources :credit_notes resources :bookings resources :shift_sales + resources :surveys get "/sales/:sale_id/manual_complete_sale" => "manual_sales#manual_complete_sale", :as => "manual_complete_sale" get "/sales/:sale_id/void" => "manual_sales#void", :as => "void" @@ -434,6 +435,9 @@ scope "(:locale)", locale: /en|mm/ do #----------- Print Setup --------# resources :print_settings + + get '/get_printer_options/:printer_name' => 'print_settings#get_printer_options' + resources :commissioners # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html end diff --git a/config/secrets.yml b/config/secrets.yml index 7930204e..076b6691 100755 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -24,8 +24,8 @@ test: # instead read values from the environment. production: secret_key_base: c4bc81065013f9a3506d385bcbd49586c42e586488144b0de90c7da36867de9fa880f46b5c4f86f0ce9b7c783bb5a73bdb0e5605a47716567294390e726d3e22 - sx_provision_url: connect.smartsales.dev/api #192.168.1.147:3002/api - server_mode: cloud + sx_provision_url: connect.smartsales.asia/api #192.168.1.147:3002/api + server_mode: application cipher_type: AES-256-CBC sx_key: Wh@t1$C2L diff --git a/config/sidekiq.yml b/config/sidekiq.yml index ac1bb2d5..672a4e9a 100755 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -8,7 +8,7 @@ --- :concurrency: 25 -:pidfile: ./tmp/pids/sidekiq.pid +:pidfile: ./tmp/sidekiq.pid :logfile: ./log/sidekiq.log :queues: - default diff --git a/data/recent_users.json b/data/recent_users.json deleted file mode 100644 index 4d2e6825..00000000 --- a/data/recent_users.json +++ /dev/null @@ -1,128 +0,0 @@ -[ - { - "id": 1, - "name": "Administrator", - "role": "administrator", - "emp_id": "999", - "password_digest": "$2a$10$mfWmxBvOHt3NbWrLGOF/POTpnxF7QEtnW99qW818dkrQqVLtjQdrS", - "token_session": null, - "session_expiry": null, - "session_last_login": "2018-03-14 09:41:25 +0630", - "created_by": "SYSTEM DEFAULT", - "created_at": "2017-11-08 09:44:30 +0630", - "updated_at": "2018-03-14 16:02:09 +0630", - "image_path": {"url":null} - }, - { - "id": 2, - "name": "Waiter", - "role": "waiter", - "emp_id": "111", - "password_digest": "$2a$10$PjBemEA2yKOcoGAyXjz81OqglrASIF8RTYHVe0vqp3FQ0T4/PzJJG", - "token_session": "662e797ad508ab6c43b1", - "session_expiry": "2018-02-21 01:45:11 +0630", - "session_last_login": "2018-02-20 13:45:11 +0630", - "created_by": "SYSTEM DEFAULT", - "created_at": "2017-11-08 09:44:30 +0630", - "updated_at": "2018-02-20 13:59:17 +0630", - "image_path": {"url":null} - }, - { - "id": 3, - "name": "Waiter 2", - "role": "waiter", - "emp_id": "222", - "password_digest": "$2a$10$gXh/Tpbr8EyJSaxsbJYVh.K7Fr4bT0A1i2mWuuZm/FHQ4D/wV1E8e", - "token_session": "61868be9530b753ada84", - "session_expiry": "2018-03-14 05:41:12 +0630", - "session_last_login": "2018-03-13 17:11:12 +0630", - "created_by": "SYSTEM DEFAULT", - "created_at": "2017-11-08 09:44:30 +0630", - "updated_at": "2018-03-13 17:32:47 +0630", - "image_path": {"url":null} - }, - { - "id": 4, - "name": "Cashier", - "role": "cashier", - "emp_id": "333", - "password_digest": "$2a$10$fHo.9wOn.yr.2Ke6iuCfou6DjpyHXwQSmZQ.43O7W4SnlmzuoIEF2", - "token_session": "693f6e98bb90b6af9978", - "session_expiry": "2018-03-15 12:36:28 +0630", - "session_last_login": "2018-03-14 16:36:28 +0630", - "created_by": "SYSTEM DEFAULT", - "created_at": "2017-11-08 09:44:30 +0630", - "updated_at": "2018-03-14 17:05:14 +0630", - "image_path": {"url":null} - }, - { - "id": 5, - "name": "manager", - "role": "manager", - "emp_id": "888", - "password_digest": "$2a$10$EaU/Sxfsb8Q3kBIAyxSEJ.ZpRC9vxSdVAFvF0WXUvWiAqHyqGggoe", - "token_session": null, - "session_expiry": null, - "session_last_login": "2018-01-16 13:37:05 +0630", - "created_by": null, - "created_at": "2017-11-30 10:03:11 +0630", - "updated_at": "2018-01-16 13:48:02 +0630", - "image_path": {"url":null} - }, - { - "id": 6, - "name": "Account", - "role": "account", - "emp_id": "777", - "password_digest": "$2a$10$bJmgIxHefkvxpxJQLQPcpurTJrp8.BwP/kirJRYb1v1thrU3TDzkC", - "token_session": null, - "session_expiry": null, - "session_last_login": "2018-01-16 10:37:22 +0630", - "created_by": null, - "created_at": "2018-01-16 10:23:09 +0630", - "updated_at": "2018-01-16 10:49:24 +0630", - "image_path": {"url":null} - }, - { - "id": 7, - "name": "Supervisor", - "role": "supervisor", - "emp_id": "666", - "password_digest": "$2a$10$/WQirOw5nu6kKDiITTVa7.IGeVyxH5JmLp3/Astu/5DlOAoMLn4Ne", - "token_session": null, - "session_expiry": null, - "session_last_login": "2018-01-16 14:28:40 +0630", - "created_by": null, - "created_at": "2018-01-16 10:23:32 +0630", - "updated_at": "2018-01-16 15:32:33 +0630", - "image_path": {"url":null} - }, - { - "id": 8, - "name": "123", - "role": "waiter", - "emp_id": "123", - "password_digest": "$2a$10$v8JBsc31XkLRNZ/QhfYBg.wbVT7CyVvk83U..0PsGiz61w0Atl/WW", - "token_session": "4fc9a18a5df511e507fc", - "session_expiry": "2018-02-01 20:08:35 +0630", - "session_last_login": "2018-02-01 14:08:35 +0630", - "created_by": null, - "created_at": "2018-02-01 14:07:16 +0630", - "updated_at": "2018-02-01 17:45:10 +0630", - "image_path": {"url":null} - }, - { - "id": 9, - "name": "Cashier 2", - "role": "cashier", - "emp_id": "444", - "password_digest": "$2a$10$5n34O09xmrIHbgvX.uhr9uAaUR8etjaqiicaXr017VWm/qDkjKVue", - "token_session": "0477edce9cf259f280c1", - "session_expiry": "2018-02-20 19:07:50 +0630", - "session_last_login": "2018-02-20 11:37:50 +0630", - "created_by": null, - "created_at": "2018-02-14 17:10:12 +0630", - "updated_at": "2018-02-20 13:37:46 +0630", - "image_path": {"url":null} - } -] \ No newline at end of file diff --git a/db/migrate/20170403183755_create_tax_profiles.rb b/db/migrate/20170403183755_create_tax_profiles.rb index 1f9dfceb..f5210bbb 100755 --- a/db/migrate/20170403183755_create_tax_profiles.rb +++ b/db/migrate/20170403183755_create_tax_profiles.rb @@ -2,6 +2,7 @@ class CreateTaxProfiles < ActiveRecord::Migration[5.1] def change create_table :tax_profiles do |t| t.string :name, :null => false + t.string :group_type, :null => false t.decimal :rate, :precision => 10, :scale => 2, :null => false, :default => 0.00 t.boolean :inclusive, :null => false, :default => false t.integer :order_by, :null => false, :default => 1 diff --git a/db/migrate/20170628103624_create_print_settings.rb b/db/migrate/20170628103624_create_print_settings.rb index 4f27bd0c..b95e4d2f 100755 --- a/db/migrate/20170628103624_create_print_settings.rb +++ b/db/migrate/20170628103624_create_print_settings.rb @@ -8,7 +8,7 @@ class CreatePrintSettings < ActiveRecord::Migration[5.1] t.string :printer_name, :null => false t.string :api_settings t.string :brand_name - t.string :type + t.string :printer_type t.decimal :page_width, :null => false, :default => 210 t.decimal :page_height, :null => false, :default => 1450 t.integer :print_copies, :null => false, :default => 1 diff --git a/db/seeds.rb b/db/seeds.rb index df707508..df5e815e 100755 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -119,8 +119,8 @@ customer2 = Customer.create({name:"TAKEAWAY", email: "cus2@customer.com", contac # room = Room.create({name:"Table 2", zone: zone2, status:"available", seater: 4 , order_by:1, created_by:"SYSTEM DEFAULT"}) #Tax Profile -tax_profiles = TaxProfile.create({id:1, name: "Commercial Tax", rate:5.0, order_by:2, created_by:"SYSTEM DEFAULT"}) -service_charges = TaxProfile.create({id:2, name: "Service Charges", rate:10.0, order_by:1, created_by:"SYSTEM DEFAULT"}) +tax_profiles = TaxProfile.create({id:1, name: "Commercial Tax", group_type: "cashier", rate:5.0, order_by:2, created_by:"SYSTEM DEFAULT"}) +service_charges = TaxProfile.create({id:2, name: "Service Charges", group_type: "cashier", rate:10.0, order_by:1, created_by:"SYSTEM DEFAULT"}) #Default menu menu = Menu.create({name: "Main Menu", is_active: true, created_by: "SYSTEM DEFAULT"}) diff --git a/lib/tasks/clear_data.rake b/lib/tasks/clear_data.rake index 43ba291e..9d476d67 100755 --- a/lib/tasks/clear_data.rake +++ b/lib/tasks/clear_data.rake @@ -20,4 +20,26 @@ namespace :clear do SeedGenerator.where("id > 1").update(:current => 0, :next => 1) puts "Clear Data Done." end + + desc "Clear Menu" + task :menu => :environment do + + + MenuItemOption.destroy_all + MenuItemAttribute.destroy_all + + MenuItemSet.destroy_all + + MenuInstanceItemSet.destroy_all + ItemSet.destroy_all + + MenuItemInstance.destroy_all + MenuItem.destroy_all + + MenuCategory.destroy_all + Menu.destroy_all + + Account.destroy_all + puts "Clear all Menu Done." + end end diff --git a/out.xls b/out.xls new file mode 100644 index 00000000..ffe4b922 Binary files /dev/null and b/out.xls differ