diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 92fab4ab..76341958 100755 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -62,9 +62,6 @@ $(document).ready(function() { clearButton: true, date: false }); - - // first input focus for all form - $("body").has("form").find("input:first").focus(); // Image Upload $("#simple_menu_item_image_path").fileinput({ @@ -107,6 +104,9 @@ $(document).ready(function() { } }); + // first input focus for all form + $('form:first *input[data-behaviour!=datepicker]:input[type!=hidden]:first').focus(); + // $(document).on("focus", "[data-behaviour~='datepicker']", function(e){ // $(this).datepicker({"format": "yyyy-M-dd", "weekStart": 1, "autoclose": true}); // $('.dropdown-toggle').dropdown(); diff --git a/app/assets/stylesheets/CRM.scss b/app/assets/stylesheets/CRM.scss index 7f9192f2..3d6fda2b 100755 --- a/app/assets/stylesheets/CRM.scss +++ b/app/assets/stylesheets/CRM.scss @@ -114,9 +114,11 @@ .green{ background-color: #009900; } -.left{ + +.left-margin-1 { margin-left:1px; } + .bottom{ margin-bottom:1px; } diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 9caef6fe..2249d049 100755 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -93,3 +93,9 @@ nav.pagination .page a:hover, text-decoration: none; } + +/*Logout Icon*/ +i.logout_icon{ + position: relative; + top: 5px; +} \ No newline at end of file diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index e097b448..6d3ac389 100755 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -262,6 +262,10 @@ select.form-control { margin-left:1px; } +.dtp-date .left{ + margin-left:0px; +} + .bottom{ margin-bottom:1px; } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 83222004..8db3e16b 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -22,9 +22,12 @@ class ApplicationController < ActionController::Base { locale: I18n.locale } end - def lookup_domain - if request.subdomain.present? && request.subdomain != "www" - @license = cache_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) # request.subdomain.downcase + def lookup_domain + + if request.subdomain.present? && request.subdomain != "www" + from = request.subdomain.downcase #+ "." + request.domain.downcase + puts from + @license = cache_license(ENV["SX_PROVISION_URL"], from) # request.subdomain.downcase if (!@license.nil?) # logger.info "Location - " + @license.name ActiveRecord::Base.establish_connection(website_connection(@license)) @@ -54,10 +57,18 @@ class ApplicationController < ActionController::Base end def cache_license(url, lookup) - @license = License.new(url, lookup) - # Export for Key - aes = MyAesCrypt.new - aes_key, aes_iv = aes.export_key(lookup) + flag = ENV["AES_IV"] + @license = License.new(url, lookup) + + # Check Exists IV + if flag == "<%= ENV['AES_IV'] %>" + # Export for Key + aes = MyAesCrypt.new + aes_key, aes_iv = aes.export_key(lookup) + else + aes_key = ENV["AES_KEY"] + aes_iv = ENV["AES_IV"] + end if (@license.detail_with_local_cache(lookup, aes_key, aes_iv) == true) return @license @@ -110,7 +121,7 @@ class ApplicationController < ActionController::Base if License.check_license_file return true else - redirect_to install_path + redirect_to activate_path end end end diff --git a/app/controllers/install_controller.rb b/app/controllers/install_controller.rb index cf16adfe..c9aeacca 100755 --- a/app/controllers/install_controller.rb +++ b/app/controllers/install_controller.rb @@ -1,42 +1,77 @@ class InstallController < BaseController + skip_before_action :verify_authenticity_token + before_action :check_license + def index end - def create + def activate + flag = "<%= ENV['AES_IV'] %>" + key_base = "<%= ENV['secret_key_base'] %>" + restaurant = params[:restaurant_name] license_key = params[:license_key] - admin_user = params[:admin_user] - admin_password = params[:admin_password] + # admin_user = params[:admin_user] + # admin_password = params[:admin_password] + db_host = params[:db_host] + db_schema = params[:db_schema] + db_user = params[:db_user] + db_password = params[:db_password] + phrase = key_base == "<%= ENV['secret_key_base'] %>"? license_key : "<%= ENV['secret_key_base'] %>" + + # Check Exists IV + if flag == "<%= ENV['AES_IV'] %>" + # Export for Key + aes = MyAesCrypt.new + aes_key, aes_iv = aes.export_key(phrase) + else + aes_key = ENV["AES_KEY"] + aes_iv = ENV["AES_IV"] + end + + @license = License.new(ENV["SX_PROVISION_URL"]) + response = @license.license_activate(aes_key, aes_iv, license_key, db_host, db_schema, db_user, db_password) + if response[:status] + redirect_to root_url, notice: response["message"] + else + redirect_to activate_path, notice: response["message"] + end end - def lookup_domain - if request.subdomain.present? && request.subdomain != "www" - @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) - if (!@license.nil?) - # logger.info "Location - " + @license.name - ActiveRecord::Base.establish_connection(website_connection(@license)) - # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema - else - # reconnect_default_db - logger.info 'License is nil' - # redirect_to root_url(:host => request.domain) + "store_error" - render :json => [{ status: false, message: 'Invalid Access!'}] - end + def check_license + if License.check_license_file + redirect_to root_url end end - def current_license(url, key) - @license = License.new(url, key) + # def lookup_domain + # if request.subdomain.present? && request.subdomain != "www" + # @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) + # if (!@license.nil?) + # # logger.info "Location - " + @license.name + # ActiveRecord::Base.establish_connection(website_connection(@license)) + # # logger.info "Connecting to - " + @license.subdomain + " - "+ @license.dbhost + "@" + @license.dbschema + # else + # # reconnect_default_db + # logger.info 'License is nil' + # # redirect_to root_url(:host => request.domain) + "store_error" + # render :json => [{ status: false, message: 'Invalid Access!'}] + # end + # end + # end - ##creating md5 hash - md5_hostname = Digest::MD5.new - md5key = md5_hostname.update(request.host) - if (@license.detail_with_local_cache(key, md5key.to_s) == true) - #if (@license.detail == true) + # def current_license(url, key) + # @license = License.new(url, key) - return @license - else - return nil - end - end + # ##creating md5 hash + # md5_hostname = Digest::MD5.new + # md5key = md5_hostname.update(request.host) + # if (@license.detail_with_local_cache(key, md5key.to_s) == true) + # #if (@license.detail == true) + + # return @license + # else + # return nil + # end + # end end diff --git a/app/controllers/oqs/edit_controller.rb b/app/controllers/oqs/edit_controller.rb index 33ffd8a6..190c4918 100755 --- a/app/controllers/oqs/edit_controller.rb +++ b/app/controllers/oqs/edit_controller.rb @@ -2,7 +2,7 @@ class Oqs::EditController < BaseOqsController def index assigned_item_id = params[:id] assigned_item = AssignedOrderItem.find(assigned_item_id) - @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_code='#{ assigned_item.item_code }'"); + @order_item = OrderItem.where("order_id='#{ assigned_item.order_id }' AND item_instance_code='#{ assigned_item.instance_code }'"); end def update @@ -17,7 +17,7 @@ class Oqs::EditController < BaseOqsController order_item.save # print - assigned_item = AssignedOrderItem.find_by_item_code(order_item.item_code) + assigned_item = AssignedOrderItem.find_by_instance_code(order_item.item_instance_code) # order queue stations oqs = assigned_item.order_queue_station @@ -25,6 +25,6 @@ class Oqs::EditController < BaseOqsController 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,assigned_item.order_id, assigned_item.item_code, print_status=" (Edited)" ) + order_queue_printer.print_order_item(print_settings, oqs,assigned_item.order_id, assigned_item.instance_code, print_status=" (Edited)" ) end end diff --git a/app/controllers/origami/credit_payments_controller.rb b/app/controllers/origami/credit_payments_controller.rb index a4978a6f..fde9d6f7 100755 --- a/app/controllers/origami/credit_payments_controller.rb +++ b/app/controllers/origami/credit_payments_controller.rb @@ -8,7 +8,7 @@ class Origami::CreditPaymentsController < BaseOrigamiController @creditcount = 0 others = 0 sale_data.sale_payments.each do |sale_payment| - if sale_payment.payment_method == "visa" + if sale_payment.payment_method == "creditnote" @creditcount = @creditcount + sale_payment.payment_amount else others = others + sale_payment.payment_amount diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index cf723fd6..8134a886 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -161,9 +161,9 @@ class Origami::DiscountsController < BaseOrigamiController sale = Sale.find(sale_id) # Check for Card Payment - is_card_payment = SaleItem.get_sale_payments_by_card(sale.sale_payments) + is_card_payment = SalePayment.get_sale_payments_by_card(sale.sale_payments) - if is_card_payment != true + if is_card != "true" account_types = Account.where("discount=?",true) table_id = sale.bookings[0].dining_facility_id table_type = DiningFacility.find(table_id).type diff --git a/app/controllers/origami/void_controller.rb b/app/controllers/origami/void_controller.rb index a243a388..27faea25 100755 --- a/app/controllers/origami/void_controller.rb +++ b/app/controllers/origami/void_controller.rb @@ -100,10 +100,5 @@ class Origami::VoidController < BaseOrigamiController end end end - end - - def void_before_pay - - end - + end end \ No newline at end of file diff --git a/app/controllers/settings/menu_item_instances_controller.rb b/app/controllers/settings/menu_item_instances_controller.rb index e4030f06..a214ffec 100755 --- a/app/controllers/settings/menu_item_instances_controller.rb +++ b/app/controllers/settings/menu_item_instances_controller.rb @@ -67,7 +67,7 @@ class Settings::MenuItemInstancesController < ApplicationController respond_to do |format| if @settings_menu_item_instances.save - @settings_menu_item_instances.item_attributes = params[:menu_item_instance][:item_attributes].reject(&:blank?) + @settings_menu_item_instances.item_attributes = params[:menu_item_instance][:item_attributes].split(" ") @settings_menu_item_instances.save format.html { redirect_to settings_menu_category_simple_menu_item_path(category,catID), notice: 'Menu item instance was successfully created.' } format.json { render :show, status: :created, location: @settings_menu_item_instances } @@ -105,9 +105,9 @@ class Settings::MenuItemInstancesController < ApplicationController end respond_to do |format| - if @settings_menu_item_instances.update(settings_menu_item_instance_params) - @settings_menu_item_instances.item_attributes = params[:menu_item_instance][:item_attributes].reject(&:blank?) + #@settings_menu_item_instances.item_attributes = params[:menu_item_instance][:item_attributes].reject(&:blank?) + @settings_menu_item_instances.item_attributes = params[:menu_item_instance][:item_attributes].split(" ") @settings_menu_item_instances.save format.html { redirect_to settings_menu_category_simple_menu_item_path(category,catID), notice: 'Menu item instance was successfully updated.' } format.json { render :show, status: :ok, location: @settings_menu_item_instances } diff --git a/app/controllers/settings/promotions_controller.rb b/app/controllers/settings/promotions_controller.rb index ec09aaab..ec00c5f6 100755 --- a/app/controllers/settings/promotions_controller.rb +++ b/app/controllers/settings/promotions_controller.rb @@ -29,8 +29,12 @@ class Settings::PromotionsController < ApplicationController def create @promotion = Promotion.new(promotion_params) @promotion.created_by = current_login_employee.id - @promotion.promo_start_hour = @promotion.promo_start_hour.to_datetime.advance(hours: +6, minutes: +30) - @promotion.promo_end_hour = @promotion.promo_end_hour.to_datetime.advance(hours: +6, minutes: +30) + if !@promotion.promo_start_hour.nil? + @promotion.promo_start_hour = @promotion.promo_start_hour.to_datetime.advance(hours: +6, minutes: +30) + end + if !@promotion.promo_end_hour.nil? + @promotion.promo_end_hour = @promotion.promo_end_hour.to_datetime.advance(hours: +6, minutes: +30) + end respond_to do |format| if @promotion.save promo_pros = @promotion.promotion_products @@ -95,16 +99,23 @@ class Settings::PromotionsController < ApplicationController def find_parent_item res = [] - item = MenuItemInstance.find_by_item_instance_code(params[:item_instance_code]) - if item.nil? + arr_inst = [] + item_inst = MenuItemInstance.find_by_item_instance_code(params[:item_instance_code]) + if item_inst.nil? product = Product.where("item_code = ?",params[:item_instance_code]).pluck(:name,:item_code) res.push(product.name) res.push(product.item_code) else - # menu_item = item.menu_item.pluck(:name,:item_code) - res.push(item.item_instance_name) - res.push(item.menu_item.item_code) + # menu_item = item_inst.menu_item.pluck(:name,:item_code) + # res.push(item_inst.item_instance_name) + # res.push(item_inst.menu_item.item_code) + item_inst.menu_item.menu_item_instances.each do |inst| + arr_inst.push({inst.item_instance_code => inst.item_instance_name}) + end + res.push({item_inst.menu_item.item_code => arr_inst}) end + puts "res" + p res render json: res end diff --git a/app/controllers/transactions/bookings_controller.rb b/app/controllers/transactions/bookings_controller.rb index 3b8e241e..63090c9c 100644 --- a/app/controllers/transactions/bookings_controller.rb +++ b/app/controllers/transactions/bookings_controller.rb @@ -4,7 +4,7 @@ class Transactions::BookingsController < ApplicationController def index - filter = params[:filter] + filter = params[:receipt_no] from = params[:from] to = params[:to] diff --git a/app/controllers/transactions/credit_notes_controller.rb b/app/controllers/transactions/credit_notes_controller.rb index 09f48d66..e35baa77 100755 --- a/app/controllers/transactions/credit_notes_controller.rb +++ b/app/controllers/transactions/credit_notes_controller.rb @@ -14,7 +14,8 @@ class Transactions::CreditNotesController < ApplicationController to = params[:to] if filter.nil? && from.nil? && to.nil? && customer.nil? - @credit_notes = Sale.where('payment_status = ?', Sale::SALE_STATUS_OUTSTANDING) + @credit_notes = Sale.where('payment_status = ?', Sale::SALE_STATUS_OUTSTANDING) + @credit_notes = Kaminari.paginate_array(@credit_notes).page(params[:page]).per(20) else sale = Sale.search_credit_sales(customer,filter,from,to) if sale.count > 0 diff --git a/app/controllers/transactions/orders_controller.rb b/app/controllers/transactions/orders_controller.rb index a76fa385..17a117bb 100755 --- a/app/controllers/transactions/orders_controller.rb +++ b/app/controllers/transactions/orders_controller.rb @@ -3,16 +3,13 @@ class Transactions::OrdersController < ApplicationController def index filter = params[:filter] - count = params[:count] from = params[:from] to = params[:to] - if filter.nil? && from.nil? && to.nil? && count.nil? + if filter.nil? && from.nil? && to.nil? orders = Order.order("order_id desc") - else - orders = Order.search(filter,from,to,count) - + orders = Order.search(filter,from,to) end if !orders.nil? diff --git a/app/jobs/order_queue_processor_job.rb b/app/jobs/order_queue_processor_job.rb index d8e5d6e1..18fdc2dd 100755 --- a/app/jobs/order_queue_processor_job.rb +++ b/app/jobs/order_queue_processor_job.rb @@ -3,9 +3,8 @@ class OrderQueueProcessorJob < ApplicationJob def perform(order_id, table_id) # Do something later - #Order ID - - order = Order.find(order_id) + #Order ID + order = Order.find(order_id) #Execute orders and send to order stations if order diff --git a/app/models/license.rb b/app/models/license.rb index 23b19aae..afb95cf4 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -21,14 +21,6 @@ class License # @secret = ENV["aes_key"] # @params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } } - end - - def shop_code - if ( self.subdomain.length > 3) - return self.subdomain[0,3].upcase - else - return self.subdomain.upcase - end end def detail_with_local_cache(lookup, key, iv) @@ -41,9 +33,11 @@ class License cache_license = nil ##Get redis connection from connection pool - Redis.current do |conn| - cache_license = conn.get(cache_key) - end + redis = Redis.new + cache_license = redis.get(cache_key) + # Redis.current do |conn| + # cache_license = conn.get(cache_key) + # end Rails.logger.info "Cache key - " + cache_key.to_s if cache_license.nil? @@ -54,22 +48,27 @@ class License @license = response.parsed_response if (@license["status"] == true) - assign() Rails.logger.info "License - " + response.parsed_response.to_s - - Redis.current do |conn| - ##Remote - store the remote response in local redis cache - conn.set(cache_key, Marshal.dump(@license)) - ##ADD to List to remove later - conn.sadd("License:cache:keys", cache_key) - end + + redis = Redis.new + redis.set(cache_key, Marshal.dump(@license)) + # redis.sadd("License:cache:keys", cache_key) + # Redis.current do |conn| + # ##Remote - store the remote response in local redis cache + # conn.set(cache_key, Marshal.dump(@license)) + # ##ADD to List to remove later + # conn.sadd("License:cache:keys", cache_key) + # end return true end - - Rails.logger.info 'API License' + else + @license = Marshal.load(cache_license) + assign() + Rails.logger.info 'API License' + return true end end @@ -80,65 +79,35 @@ class License if has_license # puts "VERIFIED" end + end - # if cache_license.nil? - # ##change the d/e key - # @params = { query: { lookup_type: self.server_mode, lookup: lookup, encrypted_key: key, iv_key: iv} } + # License Activation + def license_activate (key, iv, license_key, db_host, db_schema, db_user, db_password) + @params = { query: { lookup_type: self.server_mode, encrypted_key: key, iv_key: iv, license_key: license_key } } + response = self.class.get("/activate", @params) + @activate = response.parsed_response - # response = self.class.get("/request_license", @params) - # @license = response.parsed_response + Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s - # if (@license["status"] == true) - - # assign() - - # Rails.logger.info "License - " + response.parsed_response.to_s - - # Redis.current do |conn| - # ##Remote - store the remote response in local redis cache - # conn.set(cache_key, Marshal.dump(@license)) - # ##ADD to List to remove later - # conn.sadd("License:cache:keys", cache_key) - # end - - # return true - # end - - # Rails.logger.info 'API License' - - # else - # @license = Marshal.load(cache_license) if cache_license - - # Rails.logger.info 'Cache License' - - # if (@license["status"] == true) - # assign() - # return true - # end - # end - # return false - end - - def detail - response = self.class.get("/subdomain", @options) - @license = response.parsed_response - - Rails.logger.debug "License - " + response.parsed_response.to_s - - - if (@license["status"] == true) - assign() - - return true - end - - return false + if (@activate["status"]) + response = create_license_file(@activate) + if(response["status"]) + sym_path = "/home/yan/symmetric/" + response = create_symmetric_config(sym_path, db_host, db_schema, db_user, db_password) + if(response["status"]) + response = run_symmetric(sym_path) + end + end + else + response = { "status": false, "message": "Activation Failed! Please contact code2lab call center!"} + end + return response end def verify_license api_token = read_license("api_token") - @options = { query: {lookup_type: "application", token: api_token} } - response = self.class.get("/verify", @options) + @params = { query: {lookup_type: "application", token: api_token} } + response = self.class.get("/verify", @params) @varified = response.parsed_response Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s @@ -152,37 +121,7 @@ class License return false end - def check_remote_license(license_key) - # @options = { query: {device: "cloud", key: license_key, skey: @secret, token: Rails.application.secrets.provision_key} } - @options = { query: {lookup_type: "application", encrypted_key: @secret, token: SECRETS_CONFIG['provision_key']} } - response = self.class.get("/license", @options) - - @license = response.parsed_response - - Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s - if (@license["status"]) - assign() - end - return @license["status"] - - end - - def verify_by_api_token(api_token) - @options = { query: {device: "SX", api_token: api_token, skey: @secret, token: SECRETS_CONFIG['provision_key']} } - response = self.class.get("/verify", @options) - - @license = response.parsed_response - - Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s - if (@license["status"]) - assign() - end - - return @license["status"] - end - #Load License is remove from the cloud license because - this license is must be validated against subdmain instead of license.data from file. - - + # Check License expired date from PROVISION SERVER def check_expired(renewal_date) if (renewal_date < Date.today) return true @@ -191,6 +130,7 @@ class License end end + # Check License File exists def self.check_license_file return File.exist?("config/license.yml") end @@ -202,13 +142,156 @@ class License File.open("config/license.yml").each do |line| if line.include? (key) decrypted_line_array = line.split(":") - decrypted_line = AESCrypt.decrypt(decrypted_line_array[1]) + decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(ENV['AES_KEY']), decode_str(ENV['AES_IV']), ENV['CIPHER_TYPE']) end end end end private + + def decode_str(str) + return Base64.decode64(str) + end + + # License File Creation + def create_license_file(response_data) + if File.exist?("config/license.yml") + delete_license_file + end + + begin + # Licese File Creation + f = File.open("config/license.yml", "w") + f.write("iv_key: #{response_data['iv_key']}\n") + f.write("shop_name: #{response_data['shop_name']}\n") + f.write("email: #{response_data['email']}\n") + f.write("telephone: #{response_data['telephone']}\n") + f.write("fax: #{response_data['fax']}\n") + f.write("address: #{response_data['address']}\n") + f.write("dbhost: #{response_data['dbhost']}\n") + f.write("dbschema: #{response_data['dbschema']}\n") + f.write("dbusername: #{response_data['dbusername']}\n") + f.write("dbpassword: #{response_data['dbpassword']}\n") + f.write("api_token: #{response_data['api_token']}\n") + f.write("app_token: #{response_data['app_token']}\n") + f.close + rescue IOError + response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} + end + response = { "status": true, "message": "Success Activation. License also created."} + end + + # Symmetric Configuration + def create_symmetric_config(sym_location, db_host, db_schema, db_user, db_password) + if File.directory? (sym_location) + begin + # sx properties create + f = File.open(sym_location + "engines/sx.properties", "w") + f.write("engine.name=sx\n") + f.write("db.driver=com.mysql.jdbc.Driver\n") + f.write("db.url=jdbc:mysql://#{db_host}/#{db_schema}?tinyInt1isBit=false\n") + f.write("db.user=#{db_user}\n") + f.write("db.password=#{db_password}\n") + f.write("registration.url=\n") + f.write("sync.url=http://#{db_host}:31415/sync/sx\n") + f.write("group.id=sx\n") + f.write("external.id=000\n") + f.write("job.purge.period.time.ms=7200000\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") + f.write("job.pull.period.time.ms=10000\n") + f.write("initial.load.create.first=true\n") + f.write("initial.load.use.extract.job.enabled=true\n") + f.close + + # read from license file + shop_name = read_license("shop_name") + dbhost = read_license("dbhost") + dbschema = read_license("dbschema") + dbusername = read_license("dbusername") + dbpassword = read_license("dbpassword") + + # shop properties create + f = File.open(sym_location + "/#{shop_name}.properties", "w") + f.write("engine.name=#{shop_name}\n") + f.write("db.driver=com.mysql.jdbc.Driver\n") + f.write("db.url=jdbc:mysql://#{dbhost}/#{dbschema}?tinyInt1isBit=false\n") + f.write("db.user=#{dbusername}\n") + f.write("db.password=#{dbpassword}\n") + f.write("registration.url=http://#{db_host}:31415/sync/sx\n") + f.write("group.id=store\n") + f.write("external.id=001\n") + f.write("job.routing.period.time.ms=5000\n") + f.write("job.push.period.time.ms=10000\n") + f.write("job.pull.period.time.ms=10000\n") + # f.write("initial.load.create.first=true\n") + # f.write("initial.load.use.extract.job.enabled=true\n") + f.close + rescue IOError + response = { "status": false, "message": "Activation is success but something is wrong. \n Please contact code2lab call center!"} + end + response = { "status": true, "message": "Success Activation. License also created."} + end + end + + # Run Symmetric + def run_symmetric(sym_path) + check_sym_proc_str = `#{sym_path + "bin/sym_service status"}` + check_sym_proc_str = check_sym_proc_str.split("\n") + sym_install_status = check_sym_proc_str[0].split(": ") + # sym_run_status = check_sym_proc_str[1].split(": ") + + # Check Sym Installed + if sym_install_status[1] == "false" + response = { "status": false, "message": "Activation is success but Symmetric service not Installed. \n Please contact code2lab call center!"} + end + + # Run Sym Service + sym_run_status = check_sym_running(check_sym_proc_str[1], sym_path) + if sym_run_status + # Create Sym Table + check_sym_table = system(sym_path + "bin/symadmin --engine sx create-sym-tables") + if check_sym_table + sym_sql = Rails.root + "db/sym_master.sql" + if File.exist? (sym_sql) + # Import Sym Sql to db and start sym + run_sym_sql = system(sym_path + "bin/dbimport --engine sx " + sym_sql) + run_sym = system(sym_path + "bin/sym") + if run_sym + response = { "status": true, "message": "Activation is success and Configuration done..."} + end + else + response = { "status": false, "message": "Activation is success but Symmetric Sql not Found. \n Please contact code2lab call center!"} + end + end + end + + end + + # Check Symmetric Running + def check_sym_running(status, sym_path) + # Run Sym Service + if status.include? "Server is already running" + return true + elsif status.include? "false" + sym_start_str = `#{sym_path + "bin/sym_service start"}` + if sym_start_str.include? "Started" + return true + else + check_sym_running(sym_start_status[0]) + end + else + return true + end + end + + # Delete License File + def delete_license_file + File.delete("config/license.yml") if File.exist?("config/license.yml") + end + + # Assign db info for Cloud def assign # self.name = @license["name"] # self.address_1 = @license["address_1"] @@ -228,17 +311,24 @@ class License ## self.plan_activation_date = Date.strptime(@license["plan_activation_date"], "%Y-%m-%d") ## self.plan_next_renewal_date = Date.strptime(@license["plan_next_renewal_date"], "%Y-%m-%d") - # self.plan_max_products = @license["plan_max_products"].to_i # self.plan_max_customers = @license["plan_max_customers"].to_i # self.plan_active_connections = @license["plan_active_connections"].to_i - salt = @license["secret_key"] + # salt = @license["secret_key"] - if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] ) - self.dbhost = AESCrypt.decrypt(@license["dbhost"], salt) - self.dbschema = AESCrypt.decrypt(@license["dbschema"], salt) - self.dbusername = AESCrypt.decrypt(@license["dbusername"], salt) - self.dbpassword = AESCrypt.decrypt(@license["dbpassword"], salt) + key = Base64.decode64(ENV['AES_KEY']) + iv = Base64.decode64(ENV['AES_IV']) + + if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] ) + host = Base64.decode64(@license["dbhost"]) + dbschema = Base64.decode64(@license["dbschema"]) + dbusername = Base64.decode64(@license["dbusername"]) + dbpassword = Base64.decode64(@license["dbpassword"]) + + self.dbhost = AESCrypt.decrypt_data(host, key, iv, ENV['CIPHER_TYPE']) + self.dbschema = AESCrypt.decrypt_data(dbschema, key, iv, ENV['CIPHER_TYPE']) + self.dbusername = AESCrypt.decrypt_data(dbusername, key, iv, ENV['CIPHER_TYPE']) + self.dbpassword = AESCrypt.decrypt_data(dbpassword, key, iv, ENV['CIPHER_TYPE']) end # self.exchange_unqiue_id = @license["exchange_unqiue_id"] diff --git a/app/models/my_aes_crypt.rb b/app/models/my_aes_crypt.rb index 7427a000..acba4974 100644 --- a/app/models/my_aes_crypt.rb +++ b/app/models/my_aes_crypt.rb @@ -1,3 +1,6 @@ +require 'openssl' +require 'base64' + class MyAesCrypt @cipher = "" @@ -7,11 +10,16 @@ class MyAesCrypt def export_key(passphrase) # We want a 256 bit key symetric key based on passphrase + # for cloud is lookup + # for local is license_key + # iv_salt = passphrase+"c2l" digest = Digest::SHA256.new - key = digest.update(passphrase) - key = digest.digest - ENV['AES_KEY'] = cipher_key = key # stores the key in key, and also sets the generated key on the @cipher - ENV['AES_IV'] = cipher_iv = @cipher.random_iv # stores the iv in iv, and also sets the generated iv on the @cipher + key_digest = digest.update(passphrase) + # iv_digest = digest.update(iv_salt) + key = key_digest.digest + # iv = iv_digest.digest + ENV['AES_KEY'] = cipher_key = Base64.encode64(key) # stores the key in key, and also sets the generated key on the @cipher + ENV['AES_IV'] = cipher_iv = Base64.encode64(@cipher.random_iv) # stores the iv in iv, and also sets the generated iv on the @cipher return cipher_key, cipher_iv end diff --git a/app/models/order.rb b/app/models/order.rb index 33022eec..dd6f6d66 100755 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -363,18 +363,18 @@ class Order < ApplicationRecord end - def self.search(filter,from,to,count) - if count.to_i > 0 - item_count = "and item_count = '#{count}'" + def self.search(filter,from,to) + if filter.blank? + keyword = '' else - item_count = '' + keyword = "order_id LIKE ? OR status LIKE ? OR order_type LIKE ? OR source='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%" end - if from.present? && to.present? - Order.where("DATE_FORMAT(date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(date,'%d-%m-%Y') <= ? #{item_count}", from,to) - elsif !from.present? && !to.present? && count.present? - Order.where("item_count = '#{count}'") + + if from.present? && to.present? + order = Order.where("DATE_FORMAT(date,'%d-%m-%Y') >= ?" + " AND DATE_FORMAT(date,'%d-%m-%Y') <= ?", from,to) + query = order.where(keyword) else - Order.where("order_id LIKE ? OR status LIKE ? OR order_type LIKE ? OR source='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%",) + where("order_id LIKE ? OR status LIKE ? OR order_type LIKE ? OR source='#{filter}'","%#{filter}%","%#{filter}%","%#{filter}%") end end diff --git a/app/models/print_setting.rb b/app/models/print_setting.rb index c326f715..a13229dc 100755 --- a/app/models/print_setting.rb +++ b/app/models/print_setting.rb @@ -1,4 +1,4 @@ class PrintSetting < ApplicationRecord # validations - validates_presence_of :name, :unique_code, :printer_name, :page_width, :page_height + validates_presence_of :name, :unique_code, :printer_name, :page_width, :page_height, :print_copies end diff --git a/app/models/printer/order_queue_printer.rb b/app/models/printer/order_queue_printer.rb index 13d8a20a..315b107c 100755 --- a/app/models/printer/order_queue_printer.rb +++ b/app/models/printer/order_queue_printer.rb @@ -1,10 +1,16 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker - def print_order_item(print_settings,oqs,order_id, item_code, print_status, options="") + def print_order_item(print_settings,oqs,order_id, instance_code, print_status, options="") #Use CUPS service #Generate PDF #Print - order_item = print_query('order_item', item_code) #OrderItem.find_by_item_code(item_code) + # Must be one print + if print_settings.print_copies == 0 + print_settings.print_copies = 1 + print_settings.save! + end + + order_item = print_query('order_item', instance_code) #OrderItem.find_by_item_code(item_code) filename = "tmp/order_item.pdf" @@ -14,12 +20,13 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker pdf.render_file filename if oqs.print_copy - self.print(filename, oqs.printer_name) - self.print(filename, oqs.printer_name) + self.print(filename, oqs.printer_name) #For print copy # pdf.render_file filename.gsub(".","-copy.") # self.print(filename.gsub(".","-copy."), oqs.printer_name) else + print_settings.print_copies = 1 + print_settings.save! self.print(filename, oqs.printer_name) end # end @@ -29,9 +36,14 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker def print_order_summary(print_settings,oqs, order_id, order_items, print_status) #Use CUPS service #Generate PDF - #Print - order=print_query('order_summary', order_id) + #Print + # Must be one print + if print_settings.print_copies == 0 + print_settings.print_copies = 1 + print_settings.save! + end + order=print_query('order_summary', order_id) # For Print Per Item if oqs.cut_per_item order.each do|odi| @@ -44,11 +56,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker pdf = OrderItemPdf.new(print_settings,odi, print_status, options, oqs.use_alternate_name) # pdf.render_file "tmp/order_item.pdf" pdf.render_file filename - if oqs.print_copy - self.print(filename, oqs.printer_name) + if oqs.print_copy self.print(filename, oqs.printer_name) # self.print(filename.gsub(".","-copy."), oqs.printer_name) else + print_settings.print_copies = 1 + print_settings.save! self.print(filename, oqs.printer_name) end #end @@ -59,12 +72,13 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker pdf = OrderSummaryPdf.new(print_settings,order, print_status, order_items, oqs.use_alternate_name) pdf.render_file filename if oqs.print_copy - self.print(filename, oqs.printer_name) - self.print(filename, oqs.printer_name) + self.print(filename, oqs.printer_name) #For print copy # pdf.render_file filename.gsub(".","-copy.") # self.print(filename.gsub(".","-copy."), oqs.printer_name) else + print_settings.print_copies = 1 + print_settings.save! self.print(filename, oqs.printer_name) end end @@ -72,6 +86,12 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker # Print for orders in booking def print_booking_summary(print_settings,oqs, booking_id, print_status) + # Must be one print + if print_settings.print_copies == 0 + print_settings.print_copies = 1 + print_settings.save! + end + order=print_query('booking_summary', booking_id) # For Print Per Item if oqs.cut_per_item @@ -89,9 +109,11 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker self.print(filename, oqs.printer_name) #For print copy - pdf.render_file filename.gsub(".","-copy.") - self.print(filename.gsub(".","-copy."), oqs.printer_name) + # pdf.render_file filename.gsub(".","-copy.") + # self.print(filename.gsub(".","-copy."), oqs.printer_name) else + print_settings.print_copies = 1 + print_settings.save! self.print(filename, oqs.printer_name) end #end @@ -105,9 +127,11 @@ class Printer::OrderQueuePrinter < Printer::PrinterWorker self.print(filename, oqs.printer_name) #For print copy - pdf.render_file filename.gsub(".","-copy.") - self.print(filename.gsub(".","-copy."), oqs.printer_name) + # pdf.render_file filename.gsub(".","-copy.") + # self.print(filename.gsub(".","-copy."), oqs.printer_name) else + print_settings.print_copies = 1 + print_settings.save! self.print(filename, oqs.printer_name) end end diff --git a/app/models/printer/printer_worker.rb b/app/models/printer/printer_worker.rb index 832e24bf..ad844cfe 100755 --- a/app/models/printer/printer_worker.rb +++ b/app/models/printer/printer_worker.rb @@ -33,7 +33,6 @@ class Printer::PrinterWorker end def print(file_path,printer_destination = nil ) - if printer_destination.nil? printer_destination = self.printer_destination end diff --git a/app/models/printer/receipt_printer.rb b/app/models/printer/receipt_printer.rb index 30bd5ed8..40a60201 100755 --- a/app/models/printer/receipt_printer.rb +++ b/app/models/printer/receipt_printer.rb @@ -74,6 +74,10 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker # print as print copies in printer setting count = printer_settings.print_copies + + # override print copies for print worker loop + print_settings.print_copies = 1 + print_settings.save! begin if count == 1 pdf.render_file "tmp/receipt_bill_#{sale_data.receipt_no}.pdf" @@ -100,7 +104,7 @@ class Printer::ReceiptPrinter < Printer::PrinterWorker #Generate PDF #Print pdf = QueueNoPdf.new(printer_settings,queue) - pdf.render_file "tmp/print_queue_no.pdf" + pdf.render_file "tmp/print_queue_no.pdf" self.print("tmp/print_queue_no.pdf") end diff --git a/app/models/sale.rb b/app/models/sale.rb index cd067d1f..46f823d1 100755 --- a/app/models/sale.rb +++ b/app/models/sale.rb @@ -449,7 +449,7 @@ class Sale < ApplicationRecord 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) else - where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%",) + where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%") end end diff --git a/app/models/sale_item.rb b/app/models/sale_item.rb index a757b7fd..f1229bfa 100755 --- a/app/models/sale_item.rb +++ b/app/models/sale_item.rb @@ -29,6 +29,7 @@ class SaleItem < ApplicationRecord def self.update_existing_item(qty, item, sale_id, type, item_price, price) sale_item = SaleItem.new sale_item.product_code = item.product_code + sale_item.item_instance_code = item.item_instance_code sale_item.product_name = item.product_name + "(#{type})" sale_item.product_alt_name = item.product_alt_name sale_item.account_id = item.account_id @@ -145,17 +146,6 @@ class SaleItem < ApplicationRecord return price,type end - # Check for Card Payment - def self.get_sale_payments_by_card(sale_payments) - - # Check for Card Payment - sale_payments.each do |sp| - if sp.payment_method == "jcb" || sp.payment_method == "mpu" || sp.payment_method == "visa" || sp.payment_method == "master" - return true; - end - end - - end # def self.get_overall_discount(sale_id) # price = 0.0 # item=SaleItem.where("product_code=?", sale_id) @@ -170,6 +160,5 @@ class SaleItem < ApplicationRecord private def generate_custom_id self.sale_item_id = SeedGenerator.generate_id(self.class.name, "SLI") - end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index cb6b1249..7840817e 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -155,6 +155,16 @@ class SalePayment < ApplicationRecord end + # Check for Card Payment + def self.get_sale_payments_by_card(sale_payments) + # Check for Card Payment + sale_payments.each do |sp| + if sp.payment_method == "jcb" || sp.payment_method == "mpu" || sp.payment_method == "visa" || sp.payment_method == "master" + return true; + end + end + end + private def cash_payment payment_status = false @@ -497,8 +507,6 @@ class SalePayment < ApplicationRecord end - - private def generate_custom_id self.sale_payment_id = SeedGenerator.generate_id(self.class.name, "SPI") diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 179e3336..93cd7ab9 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -5,7 +5,7 @@ class CloseCashierPdf < Prawn::Document self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_height = printer_settings.page_height self.margin = 5 - self.price_width = 40 + self.price_width = 60 self.qty_width = 20 self.total_width = 40 self.item_width = self.page_width - ((self.price_width + self.qty_width + self.total_width)) @@ -133,7 +133,6 @@ class CloseCashierPdf < Prawn::Document text "#{shift_sale.cash_in}", :size => self.item_font_size, :align => :right end - y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Cash Out:", :size => self.item_font_size, :align => :right @@ -142,26 +141,11 @@ class CloseCashierPdf < Prawn::Document text "#{shift_sale.cash_out}", :size => self.item_font_size, :align => :right end - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Net Sales:", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{shift_sale.nett_sales}", :size => self.item_font_size, :align => :right - end - - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Total Tax :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{shift_sale.total_taxes}", :size => self.item_font_size, :align => :right - end - move_down -5 stroke_horizontal_rule move_down 7 + @total_foc = 0 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Cash Payment :", :size => self.item_font_size, :align => :right @@ -180,14 +164,7 @@ class CloseCashierPdf < Prawn::Document #start other payment details if shift_sale.other_sales > 0 other_payment.each do |other| - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Other Payment Details", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "", :size => self.item_font_size, :align => :right - end - + @total_foc = other.foc_amount.round(2) y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "MPU Payment :", :size => self.item_font_size, :align => :right @@ -204,14 +181,6 @@ class CloseCashierPdf < Prawn::Document text "#{other.visa_amount.round(2)}", :size => self.item_font_size, :align => :right end - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "JCB Payment :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{other.jcb_amount.round(2)}", :size => self.item_font_size, :align => :right - end - y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Master Payment :", :size => self.item_font_size, :align => :right @@ -220,6 +189,14 @@ class CloseCashierPdf < Prawn::Document text "#{other.master_amount.round(2)}", :size => self.item_font_size, :align => :right end + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "JCB Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{other.jcb_amount.round(2)}", :size => self.item_font_size, :align => :right + end + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do text "Reedem Payment :", :size => self.item_font_size, :align => :right @@ -227,15 +204,6 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{other.paypar_amount.round(2)}", :size => self.item_font_size, :align => :right end - - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "FOC :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{other.foc_amount.round(2)}", :size => self.item_font_size, :align => :right - end - end else y_position = cursor @@ -247,22 +215,54 @@ class CloseCashierPdf < Prawn::Document end end + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Rounding Adjustments :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{shift_sale.total_rounding.round(2)}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total :", :style => :bold, :size => self.header_font_size - 1, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{shift_sale.grand_total.round(2)}", :style => :bold, :size => self.header_font_size - 1, :align => :right + end + # end other payment details move_down -5 stroke_horizontal_rule move_down 7 - #start total amount by Account Like Food / Beverage /.. - total_amount_by_account.each do |amount| + + #start service charges and commercial tax + sale_taxes.each do |tax| y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Total #{amount.account_name} Amount:", :size => self.item_font_size, :align => :right + text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{amount.total_price.round(2)} ", :size => self.item_font_size, :align => :right + text "#{tax.st_amount.round(2)}", :size => self.item_font_size, :align => :right end end - #end total amount by Account + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Taxes :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{shift_sale.total_taxes}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Net Sales :", :style => :bold, :size => self.header_font_size - 1, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{shift_sale.nett_sales}", :style => :bold , :size => self.header_font_size - 1, :align => :right + end + #end for service charges and commercial tax #COMMENTED FOR NO NEED AND NOT CORRECT WHEN OTHER CHARGES # y_position = cursor # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do @@ -305,47 +305,66 @@ class CloseCashierPdf < Prawn::Document y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Total Overall Discount :", :size => self.item_font_size, :align => :right + text "Total Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{@overall}", :size => self.item_font_size, :align => :right + end + + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total FOC :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "(#{@total_foc})", :size => self.item_font_size, :align => :right end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Total Discount Amount :", :size => self.item_font_size, :align => :right + text "Total Void :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{shift_sale.total_discounts}", :size => self.item_font_size, :align => :right + text "(#{shift_sale.total_void})", :size => self.item_font_size, :align => :right end + + # y_position = cursor + # bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + # text "Grand Total :", :size => self.item_font_size, :align => :right + # end + # bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + # text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right + # end move_down -5 stroke_horizontal_rule move_down 7 - sale_taxes.each do |tax| - + #start total amount by Account Like Food / Beverage /.. + total_amount_by_account.each do |amount| y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "#{tax.tax_name} :", :size => self.item_font_size, :align => :right + text "Total #{amount.account_name} Amount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{tax.st_amount.round(2)}", :size => self.item_font_size, :align => :right + text "#{amount.total_price.round(2)} ", :size => self.item_font_size, :align => :right end end + #end total amount by Account + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Rounding Adjustment :", :size => self.item_font_size, :align => :right + text "Total Dine-in Count :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{shift_sale.total_rounding.round(2)}", :size => self.item_font_size, :align => :right + text "#{shift_sale.dining_count}", :size => self.item_font_size, :align => :right end - y_position = cursor + + y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Grand Total :", :size => self.item_font_size, :align => :right + text "Total Takeaway Count :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right + text "#{shift_sale.takeaway_count}", :size => self.item_font_size, :align => :right end y_position = cursor @@ -356,31 +375,7 @@ class CloseCashierPdf < Prawn::Document text "#{shift_sale.total_receipt}", :size => self.item_font_size, :align => :right end - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Dining Count :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{shift_sale.dining_count}", :size => self.item_font_size, :align => :right - end - - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Takeaway Count :", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "#{shift_sale.takeaway_count}", :size => self.item_font_size, :align => :right - end - - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Total Void:", :size => self.item_font_size, :align => :right - end - bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do - text "(#{shift_sale.total_void})", :size => self.item_font_size, :align => :right - end - - move_down 5 + move_down 5 stroke_horizontal_rule move_down 5 move_down 5 diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 091d8e51..89900056 100755 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -11,7 +11,7 @@
| Card Sale : | -- <% @sale_data.each do |data| %> - <%= data["card"] %> - <% end %> - | -
| <%= payment.payment_method.to_s.capitalize %> Sale : | @@ -167,6 +158,16 @@ <% end %> <% end %> <% end %> + |
| Card Sale : | ++ <% total_card = 0.0 %> + <% @sale_data.each do |data| %> + <% total_card = data["card"] %> + <% break end %> + <%= total_card.to_f %> + | +