diff --git a/Gemfile b/Gemfile index 41682d12..6005cae2 100644 --- a/Gemfile +++ b/Gemfile @@ -52,6 +52,7 @@ gem 'rubyzip', '= 1.0.0' gem 'axlsx', '= 2.0.1' gem 'axlsx_rails' gem 'roo' +gem 'pdfjs_viewer-rails' #Reporting gem #gem 'compendium' #gem "cancan" diff --git a/Gemfile.lock b/Gemfile.lock index eee001d1..b7f4b2ca 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -125,6 +125,7 @@ GEM thor (>= 0.14, < 2.0) jquery-ui-rails (6.0.1) railties (>= 3.2.16) + json (2.1.0) kaminari (1.0.1) activesupport (>= 4.1.0) kaminari-actionview (= 1.0.1) @@ -168,6 +169,10 @@ GEM nokogiri (1.8.1) mini_portile2 (~> 2.3.0) pdf-core (0.7.0) + pdfjs_viewer-rails (0.2.0) + json (> 1.8.4) + rails (> 4.2.0) + sass-rails (~> 5.0) pg (0.21.0) prawn (2.2.2) pdf-core (~> 0.7.0) @@ -333,6 +338,7 @@ DEPENDENCIES momentjs-rails mysql2 (>= 0.3.18, < 0.5) nested_form + pdfjs_viewer-rails pg prawn prawn-table diff --git a/Main Menu.xlsx b/Main Menu.xlsx deleted file mode 100644 index 94c70338..00000000 Binary files a/Main Menu.xlsx and /dev/null differ diff --git a/app/controllers/api/api_controller.rb b/app/controllers/api/api_controller.rb index 973fc159..2340abd4 100755 --- a/app/controllers/api/api_controller.rb +++ b/app/controllers/api/api_controller.rb @@ -1,7 +1,7 @@ class Api::ApiController < ActionController::API include TokenVerification - before_action :lookup_domain + # before_action :lookup_domain helper_method :current_token, :current_login_employee, :get_cashier private diff --git a/app/controllers/concerns/token_verification.rb b/app/controllers/concerns/token_verification.rb index 2c17e258..f8602ded 100755 --- a/app/controllers/concerns/token_verification.rb +++ b/app/controllers/concerns/token_verification.rb @@ -13,12 +13,12 @@ module TokenVerification authenticate_token || render_unauthorized end - def authenticate_token + def authenticate_token authenticate_with_http_token do |token, options| # Rails.logger.debug "token - " + token.to_s if(options.length !=0 && options["from"] == "DOEMAL") if(ENV["SERVER_MODE"] === "cloud") - from = request.subdomain.downcase + "." + request.domain.downcase + from = "local" #request.subdomain.downcase + "." + request.domain.downcase aes = MyAesCrypt.new return aes.checkKeyForAuth(from, token) end diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index fefb973e..537703a1 100755 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -169,6 +169,8 @@ class Origami::CustomersController < BaseOrigamiController sale_audit = SaleAudit.record_audit_for_edit(sale.sale_id,sale.cashier_id, action_by,remark,"PAYBYACCOUNT" ) end @out = membership_data + + render json: JSON.generate({:status => membership_data["status"], :message => membership_data["message"]}) end end end diff --git a/app/controllers/origami/dinga_controller.rb b/app/controllers/origami/dinga_controller.rb index 448b39dd..586403f9 100644 --- a/app/controllers/origami/dinga_controller.rb +++ b/app/controllers/origami/dinga_controller.rb @@ -4,32 +4,32 @@ class Origami::DingaController < BaseOrigamiController payment_method = params[:payment_method] @cashier_type = params[:type] @membership_rebate_balance=0 - sale_data = Sale.find_by_sale_id(@sale_id) - @receipt_no = sale_data.receipt_no + @sale_data = Sale.find_by_sale_id(@sale_id) + @receipt_no = @sale_data.receipt_no @shop = Shop.first # if @shop.is_rounding_adj - # new_total = Sale.get_rounding_adjustment(sale_data.grand_total) + # new_total = Sale.get_rounding_adjustment(@sale_data.grand_total) # else - # new_total = sale_data.grand_total + # new_total = @sale_data.grand_total # end - # @rounding_adj = new_total-sale_data.grand_total - @rounding_adj = sale_data.rounding_adjustment + # @rounding_adj = new_total-@sale_data.grand_total + @rounding_adj = @sale_data.rounding_adjustment @payparcount = 0 others = 0 - sale_data.sale_payments.each do |sale_payment| + @sale_data.sale_payments.each do |sale_payment| if sale_payment.payment_method == "dinga" @payparcount = @payparcount + sale_payment.payment_amount else others = others + sale_payment.payment_amount end end - @payment_prices = sale_data.grand_total - @payparcount -others + @payment_prices = @sale_data.grand_total - @payparcount -others - if sale_data - if sale_data.customer_id - customer_data= Customer.find_by_customer_id(sale_data.customer_id) + if @sale_data + if @sale_data.customer_id + customer_data= Customer.find_by_customer_id(@sale_data.customer_id) if customer_data @membership_id = customer_data.membership_id if !@membership_id.nil? @@ -73,6 +73,7 @@ def create cash = params[:payment_amount] sale_id = params[:sale_id] transaction_ref = params[:transaction_ref] + account_no = params[:account_no] if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop.first @@ -85,7 +86,7 @@ def create # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - status, @sale = sale_payment.process_payment(saleObj, @user, cash, "dinga",transaction_ref) + status, @sale = sale_payment.process_payment(saleObj, @user, cash, "dinga",account_no) if status == true @out = true, "Success!" else diff --git a/app/controllers/origami/paymal_controller.rb b/app/controllers/origami/paymal_controller.rb index 65af0c3b..1321cf87 100644 --- a/app/controllers/origami/paymal_controller.rb +++ b/app/controllers/origami/paymal_controller.rb @@ -73,6 +73,8 @@ def create cash = params[:payment_amount] sale_id = params[:sale_id] transaction_ref = params[:transaction_ref] + account_no = params[:account_no] + puts params.to_json if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) shop_details = Shop.first @@ -86,7 +88,7 @@ def create # saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - status, @sale = sale_payment.process_payment(saleObj, @user, cash, "paymal",transaction_ref) + status, @sale = sale_payment.process_payment(saleObj, @user, cash, "paymal",account_no) if status == true @out = true, "Success!" else diff --git a/app/controllers/settings/menus_controller.rb b/app/controllers/settings/menus_controller.rb index 0264084c..bc92a959 100755 --- a/app/controllers/settings/menus_controller.rb +++ b/app/controllers/settings/menus_controller.rb @@ -167,8 +167,9 @@ class Settings::MenusController < ApplicationController # end end - p.serialize("tmp/menus/" + menu.name + ".xlsx") - render :json => {status: true} + file_path = "public/menus/" + menu.name + ".xlsx" + p.serialize(file_path) + render :json => { status: true, path: file_path } end def import diff --git a/app/models/menu.rb b/app/models/menu.rb index 8bf616c9..28b23c76 100755 --- a/app/models/menu.rb +++ b/app/models/menu.rb @@ -160,7 +160,7 @@ class Menu < ApplicationRecord account = Account.create({title: row["Account"], account_type: "0"}) end - menu_itm = MenuItem.create(item_code: row["Item Code"], name: row["Item Name"], account_id: account.id, alt_name: row["Item AltName"], image_path: "", description: '', information: '', unit: '', type: "SimpleMenuItem", menu_category_id: menu_cat.id, item_attributes: "[]", item_options: "[]", account_id: account_id, is_sub_item: 0, is_available: 1, created_by: created_by) + menu_itm = MenuItem.create(item_code: row["Item Code"], name: row["Item Name"], account_id: account.id, alt_name: row["Item AltName"], image_path: "", description: '', information: '', unit: '', type: "SimpleMenuItem", menu_category_id: menu_cat.id, item_attributes: "[]", item_options: "[]", is_sub_item: 0, is_available: 1, created_by: created_by) # else # status = status + "Item Code already exists for " + row["Item Name"] + "." end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 201a1b57..29d755d7 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -197,13 +197,14 @@ class SalePayment < ApplicationRecord def self.create_payment(paypar_url,token,membership_id,received_amount,sale_id) membership_actions_data = MembershipAction.find_by_membership_type("create_payment"); - + sale_data = Sale.find_by_sale_id(sale_id) + customer_data = Customer.find_by_customer_id(sale_data.customer_id) if !membership_actions_data.nil? url = paypar_url.to_s + membership_actions_data.gateway_url.to_s merchant_uid = membership_actions_data.merchant_account_id auth_token = membership_actions_data.auth_token - sale_data = Sale.find_by_sale_id(sale_id) + if sale_data others = 0 @@ -211,14 +212,27 @@ class SalePayment < ApplicationRecord others = others + sale_payment.payment_amount end payment_prices = sale_data.grand_total - others - # Control for Paypar Cloud - begin - response = HTTParty.post(url, - :body => { membership_id:membership_id, + + if membership_id.to_i <= 0 + membership_id = customer_data.membership_id + params = { membership_id:membership_id, amount:received_amount, receipt_no:sale_data.receipt_no, merchant_uid:merchant_uid, - auth_token:auth_token}.to_json, + auth_token:auth_token}.to_json + else + params = { account_no:membership_id, + amount:received_amount, + receipt_no:sale_data.receipt_no, + merchant_uid:merchant_uid, + auth_token:auth_token}.to_json + end + + + # Control for Paypar Cloud + begin + response = HTTParty.post(url, + :body => params, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json; version=3' @@ -242,7 +256,7 @@ class SalePayment < ApplicationRecord response =false; end - Rails.logger.debug "Payment response" + Rails.logger.debug "Create Payment response" Rails.logger.debug response.to_json return response; @@ -390,9 +404,13 @@ class SalePayment < ApplicationRecord payment_status = false #Next time - validate if the vochure number is valid - within - customer_data = Customer.find_by_customer_id(self.sale.customer_id) + # customer_data = Customer.find_by_customer_id(self.sale.customer_id) + account_no = self.payment_reference + # if account_no.to_i <= 0 + # account_no = customer_data.membership_id + # end membership_setting = MembershipSetting.find_by_membership_type("paypar_url") - membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id) + membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,account_no,self.received_amount,self.sale.sale_id) #record an payment in sale-audit remark = "#{membership_data} PayMal Payment- for Customer #{self.sale.customer_id} Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} " @@ -433,9 +451,16 @@ class SalePayment < ApplicationRecord payment_status = false #Next time - validate if the vochure number is valid - within - customer_data = Customer.find_by_customer_id(self.sale.customer_id) + + # customer_data = Customer.find_by_customer_id(self.sale.customer_id) + + account_no = self.payment_reference + # if account_no == 0 + # account_no = customer_data.customer_id + # end + membership_setting = MembershipSetting.find_by_membership_type("paypar_url") - membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,customer_data.membership_id,self.received_amount,self.sale.sale_id) + membership_data = SalePayment.create_payment(membership_setting.gateway_url,membership_setting.auth_token,account_no,self.received_amount,self.sale.sale_id) #record an payment in sale-audit remark = "#{membership_data} Dinga Payment- for Customer #{self.sale.customer_id} Sale Id [#{self.sale.sale_id}]| pay amount -> #{self.received_amount} " diff --git a/app/views/origami/dinga/index.html.erb b/app/views/origami/dinga/index.html.erb index 6a4fc12b..1a7bd798 100644 --- a/app/views/origami/dinga/index.html.erb +++ b/app/views/origami/dinga/index.html.erb @@ -46,6 +46,8 @@ +
<%=@sale_id %>
+<%=@sale_data.receipt_no %>