diff --git a/app/assets/javascripts/OQS.js b/app/assets/javascripts/OQS.js index ce844239..831f2f5f 100755 --- a/app/assets/javascripts/OQS.js +++ b/app/assets/javascripts/OQS.js @@ -66,28 +66,28 @@ $(document).on('turbolinks:load', function() { } var date = new Date(data[field]["created_at"]); - var show_date = date.getDate() + "-" + date.getMonth() + "-" + date.getFullYear() + ' ' + date.getHours()+ ':' + date.getMinutes(); + var show_date = date.getDate() + "-" + date.getMonth() + "-" + date.getFullYear() + ' ' + date.getHours()+ ':' + date.getMinutes(); row ='
' + +''+ data[field]["item_name"] +'- ' + +' [x'+ data[field]["qty"] +'] ' + +'
' +'' +'' - +'Order at' - +''+ show_date +' - ' + +'Order at - ' + +''+ show_date +'' + +''+ items[field]["item_name"] +'- ' + +' [x'+ items[field]["qty"] +'] ' + +'
' +'' +'' - +'Order at' - +''+ show_date +' - ' + +'Order at - ' + +''+ show_date +''+ items[field]["customer_name"] +'
' +''+ items[field]["assigned_order_item_id"] +'
' @@ -73,8 +74,12 @@ App.order_queue_station = App.cable.subscriptions.create('OrderQueueStationChann var $divs = $("div.queue_station"); var SortListDivs = $divs.sort(function (a, b) { + first = $(a).attr('data-date'); next = $(b).attr('data-date'); + console.log(first); + console.log("hi") + console.log(next); return parseInt(next.substring(4, 16)) - parseInt(first.substring(4, 16)); }); $("#oqs_container").html(SortListDivs); diff --git a/app/assets/stylesheets/OQS.scss b/app/assets/stylesheets/OQS.scss index bd62ff95..8258a2df 100755 --- a/app/assets/stylesheets/OQS.scss +++ b/app/assets/stylesheets/OQS.scss @@ -21,6 +21,51 @@ color: #fff !important; background-color: blue; } +.cashier_number{ + width: 33%; + height:58px; + line-height:58px; + text-align:center; + background:#54A5AF; + // float:left; + // margin:2px; + font-size:20px; + color:white; + // cursor:pointer; +} +.del_cashier_number{ + opacity:0.6, +} +.pay{ + width: 86%; + height:174px; + line-height:174px; + text-align:center; + font-size:20px; + color:white; +} +.long{ + width:43%; +} +.orange{ + background-color:#FF7F50; +} +.red { + background-color:#F44336; +} +.green{ + background-color: #009900; +} +.left{ + margin-left:1px; +} + +.bottom{ + margin-bottom:1px; +} +.border-left{ + border-left:1px solid #fff; +} diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index b7bcb027..9caef6fe 100755 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -63,4 +63,33 @@ select:focus { border-top: .375em solid #111; pointer-events: none; } -} \ No newline at end of file +} + +/*Pagination*/ +nav.pagination { + margin:10px; + +} +nav.pagination .current{ + background-color:#1f91f3; + color:#fff; + padding:4px 10px; + margin-top:-4px; +} +nav.pagination .page a,.next a,.last a,.prev a,.first a{ + padding:6.5px 10px; + margin-left: 3px; +} + +nav.pagination .page a:hover, +a:focus { + background-color: #ccc; + text-decoration: none; + +} +nav.pagination .page a:hover, +.first a:hover,.last a:hover,.prev a:hover,.next a:hover{ + background-color: #ccc; + text-decoration: none; + +} diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index d378a694..83222004 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception # lookup domain for db from provision - before_action :check_license, :lookup_domain, :set_locale + before_action :lookup_domain, :set_locale helper_method :current_company,:current_login_employee,:current_user # alias_method :current_user, :current_login_employee,:current_user @@ -24,7 +24,7 @@ class ApplicationController < ActionController::Base def lookup_domain if request.subdomain.present? && request.subdomain != "www" - @license = current_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) + @license = cache_license(ENV["SX_PROVISION_URL"], request.subdomain.downcase) # request.subdomain.downcase if (!@license.nil?) # logger.info "Location - " + @license.name ActiveRecord::Base.establish_connection(website_connection(@license)) @@ -35,19 +35,31 @@ class ApplicationController < ActionController::Base # redirect_to root_url(:host => request.domain) + "store_error" render :json => [{ status: false, message: 'Invalid Access!'}] end + else + # check for license file + if check_license + current_license(ENV["SX_PROVISION_URL"]) + end end end - def current_license(url, subdomain) - @license = License.new(url, subdomain) + def current_license(url) + @license = License.new(url) - ##creating md5 hash - # md5_hostname = Digest::MD5.new - # md5key = md5_hostname.update(request.host) + if (@license.detail_with_local_file() == true) + puts "RUN SAY BYAR" + else + return nil + end + end - # if (@license.detail_with_local_cache(subdomain, md5key.to_s) == true) - #if (@license.detail == true) - if (@license.detail_with_local_cache(subdomain) == true) + def cache_license(url, lookup) + @license = License.new(url, lookup) + # Export for Key + aes = MyAesCrypt.new + aes_key, aes_iv = aes.export_key(lookup) + + if (@license.detail_with_local_cache(lookup, aes_key, aes_iv) == true) return @license else return nil @@ -96,9 +108,7 @@ class ApplicationController < ActionController::Base private def check_license if License.check_license_file - # if !License.check_license_valid - # redirect_to install_path - # end + return true else redirect_to install_path end diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 2a0626dd..d8ee10fb 100755 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -137,7 +137,7 @@ class Crm::CustomersController < BaseCrmController :body => member_params, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10 ) @@ -241,9 +241,10 @@ end url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, - member_group_id: member_group_id, - merchant_uid:merchant_uid,auth_token:auth_token}.to_json + dob: dob,address: address,nrc:nrc,card_no:card_no, + member_group_id: member_group_id, + id:id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json # Check for paypar account exists # if paypar_account_no != nil || paypar_account_no != '' @@ -252,6 +253,7 @@ end dob: dob,address: address,nrc:nrc,card_no:card_no, paypar_account_no: paypar_account_no, member_group_id: member_group_id, + id:id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json end @@ -260,7 +262,7 @@ end :body => member_params, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10 ) @@ -273,7 +275,8 @@ end rescue SocketError response = { status: false} end - + puts "ssssssss" + puts response.to_json customer = Customer.find(@crm_customer.customer_id) if response["status"] == true @@ -299,9 +302,10 @@ end url = membership.gateway_url.to_s + memberaction.gateway_url.to_s member_params = { name: name,phone: phone,email: email, - dob: dob,address: address,nrc:nrc,card_no:card_no, - member_group_id: member_group_id, - merchant_uid:merchant_uid,auth_token:auth_token}.to_json + dob: dob,address: address,nrc:nrc,card_no:card_no, + member_group_id: member_group_id, + id:id, + merchant_uid:merchant_uid,auth_token:auth_token}.to_json # Check for paypar account exists if paypar_account_no.present? @@ -309,6 +313,7 @@ end dob: dob,address: address,nrc:nrc,card_no:card_no, paypar_account_no: paypar_account_no, member_group_id: member_group_id, + id:id, merchant_uid:merchant_uid,auth_token:auth_token}.to_json end @@ -317,7 +322,7 @@ end :body => member_params, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10 ) @@ -331,7 +336,17 @@ end response = { status: false} end + puts "ssssssss" + puts response.to_json + if response["status"] == true + customer = Customer.find(@crm_customer.customer_id) + # Check membership id and bind to user + if response["membership_id"] != nil + status = customer.update_attributes(membership_id: response["membership_id"],membership_type:member_group_id ) + else + status = customer.update_attributes(membership_type:member_group_id ) + end format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated.' } format.json { render :show, status: :ok, location: @crm_customer } else diff --git a/app/controllers/origami/addorders_controller.rb b/app/controllers/origami/addorders_controller.rb index ff917887..7bde1e98 100755 --- a/app/controllers/origami/addorders_controller.rb +++ b/app/controllers/origami/addorders_controller.rb @@ -67,7 +67,7 @@ class Origami::AddordersController < ApplicationController#BaseOrigamiController @order.guest = params[:guest_info] @order.table_id = params[:table_id] # this is dining facilities's id @order.new_booking = true - @order.employee_name = current_login_employee.name + @order.waiters = current_login_employee.name #Create Table Booking or Room Booking if !params["booking_id"].nil? # check booking id is already completed. diff --git a/app/controllers/origami/discounts_controller.rb b/app/controllers/origami/discounts_controller.rb index 44ddd60e..82e878bd 100755 --- a/app/controllers/origami/discounts_controller.rb +++ b/app/controllers/origami/discounts_controller.rb @@ -6,7 +6,9 @@ class Origami::DiscountsController < BaseOrigamiController sale_id = params[:id] if Sale.exists?(sale_id) @sale_data = Sale.find(sale_id) + @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) end + @member_discount = MembershipSetting.find_by_discount(1) @accounts = Account.all end @@ -197,7 +199,7 @@ class Origami::DiscountsController < BaseOrigamiController auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10) rescue HTTParty::Error response = {"status": false, "message": "Can't open membership server " } @@ -213,7 +215,8 @@ class Origami::DiscountsController < BaseOrigamiController else response = {"status": false, "message": "You have no selected discount item" } end - + puts "discount" + puts response.to_json # Re-calc All Amount in Sale if response["status"] == true discount_amount = response["discount_earned"] @@ -227,7 +230,7 @@ class Origami::DiscountsController < BaseOrigamiController else result = {:status=> response["message"],:title=>"Alert", :table_id => table_id,:table_type => table_type } end - + render :json => result.to_json end #end Is Card Payment diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 27b9cc52..febf7e45 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -24,6 +24,7 @@ class Origami::HomeController < BaseOrigamiController @dining.bookings.active.each do |booking| if booking.sale_id.nil? && booking.booking_status != 'moved' + @order_items = Array.new booking.booking_orders.each do |booking_order| order = Order.find(booking_order.order_id) @@ -31,26 +32,42 @@ class Origami::HomeController < BaseOrigamiController @obj_order = order @customer = order.customer @date = order.created_at + @booking= booking order.order_items.each do |item| @order_items.push(item) end + accounts = @customer.tax_profiles + @account_arr =[] + accounts.each do |acc| + account = TaxProfile.find(acc) + @account_arr.push(account) + end end end @status_order = 'order' else sale = Sale.find(booking.sale_id) if sale.sale_status != "completed" && sale.sale_status != 'void' + @sale_array.push(sale) if @status_order == 'order' @status_order = 'sale' end + @booking= booking @date = sale.created_at @status_sale = 'sale' @obj_sale = sale @customer = sale.customer + accounts = @customer.tax_profiles + @account_arr =[] + accounts.each do |acc| + account = TaxProfile.find(acc) + @account_arr.push(account) + end end end end + end private diff --git a/app/controllers/origami/other_charges_controller.rb b/app/controllers/origami/other_charges_controller.rb index c402782d..c7e20ba6 100755 --- a/app/controllers/origami/other_charges_controller.rb +++ b/app/controllers/origami/other_charges_controller.rb @@ -5,6 +5,7 @@ class Origami::OtherChargesController < BaseOrigamiController sale_id = params[:sale_id] if Sale.exists?(sale_id) @sale_data = Sale.find(sale_id) + @table = DiningFacility.find(@sale_data.bookings[0].dining_facility_id) end end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index d6671700..428dc322 100755 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -81,7 +81,7 @@ class Origami::PaymentsController < BaseOrigamiController # get member information rebate = MembershipSetting.find_by_rebate(1) if customer.membership_id != nil && rebate - member_info = Customer.get_member_account(customer) + member_info = Customer.get_member_account(customer) rebate_amount = Customer.get_membership_transactions(customer,saleObj.receipt_no) end @@ -116,12 +116,20 @@ class Origami::PaymentsController < BaseOrigamiController #get customer amount @customer = Customer.find(@sale_data.customer_id) + accounts = @customer.tax_profiles + @account_arr =[] + accounts.each do |acc| + account = TaxProfile.find(acc) + @account_arr.push(account) + end + rebate = MembershipSetting.find_by_rebate(1) # get member information if @customer.membership_id != nil && rebate response = Customer.get_member_account(@customer) + puts response.to_json if response["status"]==true - response["data"].each do |res| + response["account_data"].each do |res| if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" @balance += res["balance"] # @accountable_type = res["accountable_type"] @@ -136,6 +144,7 @@ class Origami::PaymentsController < BaseOrigamiController @sale_data.bookings.each do |sbk| df = DiningFacility.find(sbk.dining_facility_id) @table_no = df.type + ' ' + df.name + @checkin_time = sbk.checkin_at break end diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index f235aee3..6c0b98c8 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -24,10 +24,12 @@ class Origami::RoomsController < BaseOrigamiController @order_items = Array.new booking.booking_orders.each do |booking_order| order = Order.find(booking_order.order_id) + @customer = order.customer if (order.status == "new") @obj_order = order - @customer = order.customer + @date = order.created_at + @booking = booking order.order_items.each do |item| @order_items.push(item) end @@ -42,6 +44,7 @@ class Origami::RoomsController < BaseOrigamiController if @status_order == 'order' @status_order = 'sale' end + @booking = booking @date = sale.created_at @status_sale = 'sale' @obj_sale = sale diff --git a/app/controllers/origami/voucher_controller.rb b/app/controllers/origami/voucher_controller.rb index f71bcf4c..421c31a0 100755 --- a/app/controllers/origami/voucher_controller.rb +++ b/app/controllers/origami/voucher_controller.rb @@ -45,7 +45,7 @@ class Origami::VoucherController < BaseOrigamiController }.to_json, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10 ) rescue Net::OpenTimeout diff --git a/app/controllers/transactions/bookings_controller.rb b/app/controllers/transactions/bookings_controller.rb new file mode 100644 index 00000000..b826cd52 --- /dev/null +++ b/app/controllers/transactions/bookings_controller.rb @@ -0,0 +1,59 @@ +class Transactions::BookingsController < ApplicationController + load_and_authorize_resource except: [:create] + before_action :set_transactions_booking, only: [:show, :edit, :update, :destroy] + + def index + + filter = params[:filter] + from = params[:from] + to = params[:to] + + if filter.nil? && from.nil? && to.nil? + @bookings = Booking.all.order("sale_id desc") + @bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(2) + else + sale = Sale.search(filter,from,to) + if sale.count > 0 + @bookings = sale + @bookings = Kaminari.paginate_array(@bookings).page(params[:page]).per(2) + else + @bookings = 0 + end + end + + respond_to do |format| + format.html # index.html.erb + format.json { render json: @bookings } + end + + end + + # GET /transactions/bookings/1 + # GET /transactions/bookings/1.json + def show + + @booking = Booking.find(params[:id]) + + @order_items = [] + @booking.booking_orders.each do |booking_order| + @order = Order.find(booking_order.order_id) + #if (order.status == "new") + @order_items = @order_items + @order.order_items + #end + end + if @booking.sale_id.present? + @sale = Sale.find(@booking.sale_id) + end + + respond_to do |format| + format.html # show.html.erb + format.json { render json: @booking } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_transactions_booking + @transactions_booking = Booking.find(params[:id]) + end +end diff --git a/app/controllers/transactions/credit_notes_controller.rb b/app/controllers/transactions/credit_notes_controller.rb index 339998f5..e28b5331 100755 --- a/app/controllers/transactions/credit_notes_controller.rb +++ b/app/controllers/transactions/credit_notes_controller.rb @@ -15,12 +15,11 @@ class Transactions::CreditNotesController < ApplicationController if filter.nil? && from.nil? && to.nil? && customer.nil? @sales = Sale.where('payment_status = ?', Sale::SALE_STATUS_OUTSTANDING) - puts "cccccccccccc" else sale = Sale.search_credit_sales(customer,filter,from,to) if sale.count > 0 @sales = sale - @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) + @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) else @sales = 0 end diff --git a/app/controllers/transactions/orders_controller.rb b/app/controllers/transactions/orders_controller.rb index bd079d83..496d43cd 100755 --- a/app/controllers/transactions/orders_controller.rb +++ b/app/controllers/transactions/orders_controller.rb @@ -9,19 +9,18 @@ class Transactions::OrdersController < ApplicationController if filter.nil? && from.nil? && to.nil? && count.nil? orders = Order.order("order_id desc") - puts "ssssss" + else orders = Order.search(filter,from,to,count) - puts "aaaaa" end if !orders.nil? - @orders = Kaminari.paginate_array(orders).page(params[:page]).per(50) + @orders = Kaminari.paginate_array(orders).page(params[:page]).per(20) else @orders = [] end - puts @orders.to_json + respond_to do |format| format.html # index.html.erb format.json { render json: @orders } diff --git a/app/controllers/transactions/sales_controller.rb b/app/controllers/transactions/sales_controller.rb index 9aca7d87..8486d9ca 100755 --- a/app/controllers/transactions/sales_controller.rb +++ b/app/controllers/transactions/sales_controller.rb @@ -11,13 +11,13 @@ class Transactions::SalesController < ApplicationController to = params[:to] if receipt_no.nil? && from.nil? && to.nil? - @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc").limit(500) - @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) + @sales = Sale.where("NOT sale_status = 'void' " ).order("sale_id desc") + @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) else sale = Sale.search(receipt_no,from,to) if sale.count > 0 @sales = sale - @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(50) + @sales = Kaminari.paginate_array(@sales).page(params[:page]).per(20) else @sales = 0 end diff --git a/app/models/AESEncDec.rb b/app/models/AESEncDec.rb deleted file mode 100644 index e175a3a9..00000000 --- a/app/models/AESEncDec.rb +++ /dev/null @@ -1,31 +0,0 @@ -require 'openssl' -require 'base64' -require 'uri' - -class AESEncDec { - cipher = OpenSSL::Cipher::Cipher.new("aes-256-cbc") - - def self.export_key - ENV['aes_key'] = cipher.key = cipher.random_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 - end - - def self.encrypt(data) - cipher.encrypt - cipher.key = ENV["aes_key"] - cipher.iv = ENV["aes_iv"] - encrypted = cipher.update(data) + cipher.final - encrypted = Base64.urlsafe_encode64(encrypted) - return encrypted - end - - def self.decrypt(data) - cipher.decrypt - cipher.key = ENV["aes_key"] - cipher.iv = ENV["aes_iv"] - - # Start the decryption - decoded = Base64.urlsafe_decode64(data) - decrypted = cipher.update(decoded) + cipher.final - end -} \ No newline at end of file diff --git a/app/models/ability.rb b/app/models/ability.rb index 1636d048..70ce4e94 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -32,6 +32,7 @@ class Ability can :manage, Order + can :manage, Booking can :manage, Sale @@ -84,7 +85,7 @@ class Ability can :read, Order can :update, Order - + can :menage, Booking can :read, Sale can :update, Sale can :get_customer, Customer diff --git a/app/models/booking.rb b/app/models/booking.rb index e3d94a37..b65063a4 100755 --- a/app/models/booking.rb +++ b/app/models/booking.rb @@ -41,6 +41,22 @@ class Booking < ApplicationRecord return new_dining.type end + def self.search(filter,from,to) + if filter.blank? + keyword = '' + else + keyword = "booking_id LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%" + 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) + else + where("receipt_no LIKE ? OR cashier_name LIKE ? OR sale_status ='#{filter}'","%#{filter}%","%#{filter}%",) + end + + end + private def generate_custom_id self.booking_id = SeedGenerator.generate_id(self.class.name, "BKI") diff --git a/app/models/customer.rb b/app/models/customer.rb index 9e629721..13e6c277 100755 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -23,13 +23,17 @@ class Customer < ApplicationRecord # urltest =self.url_exist?(url) begin - response = HTTParty.get(url, :body => { membership_id: customer.membership_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - }, - :timeout => 10 - ) + response = HTTParty.get(url, :body => { + membership_id: customer.membership_id, + merchant_uid:merchant_uid, + type: "summary", + auth_token:auth_token + }.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json; version=2' + }, + :timeout => 10) rescue HTTParty::Error response = {status: false, message: "Server Error"} @@ -63,7 +67,7 @@ class Customer < ApplicationRecord }.to_json, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10 ) @@ -91,7 +95,7 @@ class Customer < ApplicationRecord auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - @customers = Customer.where("membership_type IS NOT NULL AND membership_id IS NULL") + @customers = Customer.where("membership_type IS NOT NULL AND membership_id IS NULL") @customers.each do |customer| member_params = { name: customer.name,phone: customer.contact_no, @@ -102,7 +106,7 @@ class Customer < ApplicationRecord # Check for paypar account exists # if paypar_account_no != nil || paypar_account_no != '' - if paypar_account_no.present? + if customer.paypar_account_no.present? member_params = { name: customer.name,phone: customer.contact_no, email: customer.email,dob: customer.date_of_birth, address: customer.address,nrc:customer.nrc_no, @@ -116,7 +120,7 @@ class Customer < ApplicationRecord :body => member_params, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }) rescue Net::OpenTimeout response = { status: false, message: "Server Time out" } @@ -127,7 +131,6 @@ class Customer < ApplicationRecord rescue SocketError response = { status: false, message: "Can't connect server"} end - if response["status"] == true status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) end @@ -161,10 +164,12 @@ class Customer < ApplicationRecord credit = 1 end end + # overall_dis = SaleItem.get_overall_discount(sObj.id) overall_dis = sObj.total_discount total_amount = rebate_prices - payparcost - overall_dis + if credit == 1 total_amount = 0 end @@ -183,7 +188,7 @@ class Customer < ApplicationRecord receipt_no: receipt_no,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10) rescue Net::OpenTimeout response = { "status": false , "message": "Connect To" } @@ -215,7 +220,7 @@ class Customer < ApplicationRecord }.to_json, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10 ) diff --git a/app/models/license.rb b/app/models/license.rb index 537e1221..31403038 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -1,7 +1,7 @@ class License include HTTParty - base_uri "secure.smartsales.asia/api" + base_uri "provision.zsai.ws/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, @@ -13,17 +13,14 @@ class License def initialize(server = "", lookup = "") #this code is hard-code to reflect server mode - Very important. - self.server_mode = ENV["server_mode"] + self.server_mode = ENV["SERVER_MODE"] if (server != "") self.class.base_uri server end - # generate key for license file encrypt - AESCrypt.export_key() - - @secret = ENV["aes_key"] - @params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } } + # @secret = ENV["aes_key"] + # @params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } } end def shop_code @@ -32,15 +29,11 @@ class License else return self.subdomain.upcase end - end + end - def self.check_license_file - return File.exist?("config/license.yml") - end - - def detail_with_local_cache(lookup) + def detail_with_local_cache(lookup, key, iv) ##Check from local redis - if available load local otherwise get from remote - cache_key = "store:license:#{@secret}:hostname" + cache_key = "#{lookup}:license:#{key}:hostname" # No Needs for current # @secret = key @@ -53,12 +46,11 @@ class License end Rails.logger.info "Cache key - " + cache_key.to_s - if cache_license.nil? ##change the d/e key - @params = { query: { lookup_type: "cloud", lookup: lookup, encrypted_key: @secret } } - - response = self.class.get("/request_license", @params) + # @options = { query: {device: "SXlite", lookup: lookup, skey: @secret, token: SECRETS_CONFIG['provision_key']} } + @params = { query: { lookup_type: self.server_mode, lookup: lookup, encrypted_key: key, iv_key: iv} } + response = self.class.get("/subdomain", @params) @license = response.parsed_response if (@license["status"] == true) @@ -78,23 +70,56 @@ class License 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_with_local_file() + has_license = true #verify_license() + + if has_license + puts "VERIFIED" + 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} } + + # response = self.class.get("/request_license", @params) + # @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 + + # 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 @@ -110,6 +135,23 @@ class License return false end + def verify_license + api_token = read_license("api_token") + @options = { query: {lookup_type: "application", token: api_token} } + response = self.class.get("/verify", @options) + @varified = response.parsed_response + + Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s + if (@varified["status"]) + if (!check_expired(@varified["plan_next_renewal_date"])) + return true + end + else + delete_license_file + end + 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']} } @@ -141,15 +183,32 @@ class License #Load License is remove from the cloud license because - this license is must be validated against subdmain instead of license.data from file. - def expired? - if (self.plan_next_renewal_date < Date.today) + def check_expired(renewal_date) + if (renewal_date < Date.today) return true else return false end end + + def self.check_license_file + return File.exist?("config/license.yml") + end - private + # read line by key for license file + def read_license(key) + decrypted_line = "" + if File.exist?("config/license.yml") + 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]) + end + end + end + end + + private def assign # self.name = @license["name"] # self.address_1 = @license["address_1"] diff --git a/app/models/my_aes_crypt.rb b/app/models/my_aes_crypt.rb new file mode 100644 index 00000000..7427a000 --- /dev/null +++ b/app/models/my_aes_crypt.rb @@ -0,0 +1,38 @@ +class MyAesCrypt + @cipher = "" + + def initialize + @cipher = OpenSSL::Cipher::Cipher.new(ENV["CIPHER_TYPE"]) + end + + def export_key(passphrase) + # We want a 256 bit key symetric key based on passphrase + 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 + return cipher_key, cipher_iv + end + + private + def encrypt(data) + cipher.encrypt + cipher.key = ENV["aes_key"] + cipher.iv = ENV["aes_iv"] + encrypted = cipher.update(data) + cipher.final + encrypted = Base64.encode64(encrypted) + return encrypted + end + + def decrypt(data) + cipher.decrypt + cipher.key = ENV["aes_key"] + cipher.iv = ENV["aes_iv"] + + # Start the decryption + decoded = Base64.decode64(data) + decrypted = cipher.update(decoded) + cipher.final + return decrypted + end +end \ No newline at end of file diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 5f97bcfc..b4b29303 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -85,7 +85,7 @@ class SalePayment < ApplicationRecord }.to_json, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10 ) rescue Net::OpenTimeout @@ -120,17 +120,18 @@ class SalePayment < ApplicationRecord # Control for Paypar Cloud begin response = HTTParty.post(url, - :body => { generic_customer_id:membership_id, + :body => { membership_id:membership_id, total_amount: redeem_prices, total_sale_transaction_amount: sale_data.grand_total, redeem_amount:received_amount, receipt_no:sale_data.receipt_no, campaign_type_id:campaign_type_id, - account_no:"",merchant_uid:merchant_uid, + account_no:"", + merchant_uid:merchant_uid, auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10 ) @@ -399,7 +400,7 @@ class SalePayment < ApplicationRecord }.to_json, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10) rescue Net::OpenTimeout response = { "status": false , "message": "Connect To" } @@ -468,7 +469,7 @@ class SalePayment < ApplicationRecord }.to_json, :headers => { 'Content-Type' => 'application/json', - 'Accept' => 'application/json' + 'Accept' => 'application/json; version=2' }, :timeout => 10) rescue Net::OpenTimeout response = { "status": false , "message": "Connect To" } diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index fe6b46b0..bcd3becf 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -295,14 +295,14 @@ class ReceiptBillPdf < Prawn::Document total = total + res["balance"] #total redeem amount if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Redeem" - redeem = redeem + res["redeem"] + redeem = redeem + res["withdraw"] balance = balance + res["balance"] end #end Total redem #total Rebate Earn if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebateAccount" && res["status"]== "Rebate" - rebate_balance = rebate_balance + res["rebate"] + rebate_balance = rebate_balance + res["deposit"] move_down 5 y_position = cursor @@ -310,20 +310,20 @@ class ReceiptBillPdf < Prawn::Document text "Rebate Earn", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["rebate"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end # Total Rebate Amount if birthday if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebateBonusAccount" && res["status"]== "Rebate" - rebate_balance = rebate_balance + res["rebate"] + rebate_balance = rebate_balance + res["deposit"] move_down 5 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["rebate"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + text "#{number_with_precision(res["deposit"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end end #end Total rebate if birthday diff --git a/app/views/layouts/_left_sidebar.html.erb b/app/views/layouts/_left_sidebar.html.erb index cf9f77c0..25b196af 100755 --- a/app/views/layouts/_left_sidebar.html.erb +++ b/app/views/layouts/_left_sidebar.html.erb @@ -77,6 +77,11 @@ <%= t :transactions %> diff --git a/app/views/oqs/edit/index.html.erb b/app/views/oqs/edit/index.html.erb index cf255912..99541e8a 100755 --- a/app/views/oqs/edit/index.html.erb +++ b/app/views/oqs/edit/index.html.erb @@ -1,5 +1,5 @@ -<%= qid.item_name %> [x <%= qid.qty %> ] - +
-
- Order at
-
+
+ Order at -
+
<%= qid.created_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") %>
- -
-
- <%= qid.item_order_by %>
+
+ Order By -
+ <%= qid.item_order_by %>
-
completed
<%= qid.customer_name %>
<%= qid.assigned_order_item_id %>
@@ -133,27 +134,27 @@| Order By | -Order At - | Customer - | |||
|---|---|---|---|---|---|
| - | - | + | Order By | +Order At | + +|
| + | + | ||||
| Table/Room | -+ | Customer | +|||