diff --git a/Gemfile b/Gemfile index b39a85a3..36be43b7 100644 --- a/Gemfile +++ b/Gemfile @@ -45,6 +45,7 @@ gem 'to_xls-rails' # Use jquery as the JavaScript library gem 'jquery-rails' +gem 'jquery-ui-rails' # Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks gem 'turbolinks', '~> 5' # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder @@ -95,6 +96,6 @@ gem 'httparty', '~> 0.15.5' # gem 'momentjs-rails', '>= 2.9.0' # gem 'bootstrap-datepicker-rails' -# gem 'momentjs-rails', '>= 2.9.0' -# gem 'bootstrap3-datetimepicker-rails', '~> 4.17.47' +# # gem 'momentjs-rails', '>= 2.9.0' +# gem 'bootstrap3-datetimepicker-rails'z gem 'bootstrap-datepicker-rails' diff --git a/Gemfile.lock b/Gemfile.lock index 4235d035..a4441893 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -80,13 +80,15 @@ GEM httparty (0.15.5) multi_xml (>= 0.5.2) i18n (0.8.4) - jbuilder (2.6.4) - activesupport (>= 3.0.0) + jbuilder (2.7.0) + activesupport (>= 4.2.0) multi_json (>= 1.2) jquery-rails (4.3.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) + jquery-ui-rails (6.0.1) + railties (>= 3.2.16) kaminari (0.16.3) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -95,20 +97,20 @@ GEM rb-inotify (~> 0.9, >= 0.9.7) loofah (2.0.3) nokogiri (>= 1.5.9) - mail (2.6.5) + mail (2.6.6) mime-types (>= 1.16, < 4) method_source (0.8.2) mime-types (3.1) mime-types-data (~> 3.2015) mime-types-data (3.2016.0521) - mini_portile2 (2.1.0) + mini_portile2 (2.2.0) minitest (5.10.2) multi_json (1.12.1) multi_xml (0.6.0) mysql2 (0.4.6) nio4r (2.1.0) - nokogiri (1.7.2) - mini_portile2 (~> 2.1.0) + nokogiri (1.8.0) + mini_portile2 (~> 2.2.0) pdf-core (0.7.0) pg (0.20.0) prawn (2.2.2) @@ -180,7 +182,7 @@ GEM activesupport (>= 3.2.1) shoulda-matchers (3.1.1) activesupport (>= 4.0.0) - sidekiq (5.0.0) + sidekiq (5.0.2) concurrent-ruby (~> 1.0) connection_pool (~> 2.2, >= 2.2.0) rack-protection (>= 1.5.0) @@ -244,6 +246,7 @@ DEPENDENCIES httparty (~> 0.15.5) jbuilder (~> 2.5) jquery-rails + jquery-ui-rails kaminari (~> 0.16.3) listen (~> 3.0.5) mysql2 (>= 0.3.18, < 0.5) diff --git a/app/assets/javascripts/CRM.js b/app/assets/javascripts/CRM.js index 66f161af..ee1c6a41 100644 --- a/app/assets/javascripts/CRM.js +++ b/app/assets/javascripts/CRM.js @@ -14,4 +14,6 @@ //= require bootstrap //= require jquery_ujs //= require turbolinks -//= require cable \ No newline at end of file +//= require cable +//= require jquery-ui +//= require bootstrap-datepicker \ No newline at end of file diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 59e4a386..a05ea4ee 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -17,11 +17,7 @@ //= require turbolinks //= require cable //= require settings/processing_items -//= require bootstrap-datepicker/core -//= require bootstrap-datepicker/locales/bootstrap-datepicker.es -$(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/javascripts/origami.js b/app/assets/javascripts/origami.js index dc3ab163..0079142f 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -15,6 +15,8 @@ //= require jquery_ujs //= require turbolinks //= require cable +//= require jquery-ui +//= require bootstrap-datepicker $(document).ready(function(){ // Enable/Disable Button @@ -209,13 +211,7 @@ $(document).ready(function(){ if(data["response_data"]["data"][i]["accountable_type"] == "RebateAccount"){ var balance = data["response_data"]["data"][i]["balance"]; console.log(balance); - if (balance == "0.0") { - $("#customer_amount").text('0.0'); - }else{ $("#customer_amount").text(balance); - } - - } }); } diff --git a/app/assets/javascripts/report.js b/app/assets/javascripts/report.js new file mode 100644 index 00000000..09f74075 --- /dev/null +++ b/app/assets/javascripts/report.js @@ -0,0 +1,4 @@ +$(document).on("focus", "[data-behaviour~='datepicker']", function(e){ + $(this).datepicker({"format": "yyyy-M-dd", "weekStart": 1, "autoclose": true}); + $('.dropdown-toggle').dropdown(); +}); \ No newline at end of file diff --git a/app/assets/stylesheets/CRM.scss b/app/assets/stylesheets/CRM.scss index f43cc3f9..a88efe96 100644 --- a/app/assets/stylesheets/CRM.scss +++ b/app/assets/stylesheets/CRM.scss @@ -1,6 +1,8 @@ @import "bootstrap"; @import "font-awesome"; @import "theme"; +@import "jquery-ui"; +@import "bootstrap-datepicker3"; /* Show it is fixed to the top */ // body { diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css new file mode 100644 index 00000000..e69de29b diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 468ac33d..6097a890 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -2,7 +2,7 @@ @import "bootstrap"; @import "font-awesome"; @import "theme"; -@import 'bootstrap-datepicker'; + /* Show it is fixed to the top */ // body { diff --git a/app/assets/stylesheets/origami.scss b/app/assets/stylesheets/origami.scss index 5e361f7e..71a9915e 100644 --- a/app/assets/stylesheets/origami.scss +++ b/app/assets/stylesheets/origami.scss @@ -1,6 +1,8 @@ @import "bootstrap"; @import "font-awesome"; @import "theme"; +@import "jquery-ui"; +@import "bootstrap-datepicker3"; /* Show it is fixed to the top */ // body { @@ -33,6 +35,10 @@ // cursor:pointer; } +.del_cashier_number{ + opacity:0.6, +} + .pay{ width: 98%; height:211px; diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index ed285f49..1f35da76 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -5,18 +5,18 @@ class Crm::CustomersController < BaseCrmController # GET /crm/customers.json def index filter = params[:filter] - + if filter.nil? @crm_customers = Customer.order("customer_id").page(params[:page]) #@products = Product.order("name").page(params[:page]).per(5) else - @crm_customers = Customer.where("name LIKE ?", "%#{filter}%").order("name").page(params[:page]) - end + @crm_customers = Customer.where("name LIKE ?", "%#{filter}%").order("name").page(params[:page]) end #@crm_customers = Customer.all @crm_customer = Customer.new - if @crm_customer.valid? - @crm_customer.errors.messages - end + + if flash["errors"] + @crm_customer.valid? + end # @membership = Customer.get_member_group # if @membership["status"] == true # @member_group = @membership["data"] @@ -31,13 +31,19 @@ class Crm::CustomersController < BaseCrmController # GET /crm/customers/1.json def show @orders = Order.where("customer_id=?", params[:id]) - + @sales = Sale.where("customer_id=?", params[:id]) + if @orders @order_items = [] - @orders.each do |bo| - @order_items = @order_items + bo.order_items + @orders.each do |order| + @order_items = @order_items + order.order_items + end + end + if @sales + @sale_items = [] + @sales.each do |sale| + @sale_items = @sale_items + sale.sale_items end - end end @@ -57,8 +63,9 @@ class Crm::CustomersController < BaseCrmController def create @crm_customers = Customer.new(customer_params) - + respond_to do |format| + puts @crm_customers.errors.to_json if @crm_customers.save name = customer_params[:name] phone = customer_params[:contact_no] @@ -72,9 +79,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, - dob: dob, - member_group_id: member_group_id,merchant_uid:merchant_uid}.to_json, :headers => { 'Content-Type' => 'application/json', @@ -83,18 +88,18 @@ class Crm::CustomersController < BaseCrmController ) if response["status"] == true - + customer = Customer.find(@crm_customers.customer_id) status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) - + if params[:sale_id] format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer', notice: 'Customer was successfully created.' } else format.html { redirect_to crm_customers_path, notice: 'Customer was successfully created'} - end + end # format.json { render :index, status: :created, location: @crm_customers } else - + @crm_customers.destroy if params[:sale_id] format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} @@ -105,8 +110,11 @@ class Crm::CustomersController < BaseCrmController else if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} + flash[:errors] = @crm_customers.errors + format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} + format.json { render json: @crm_customers.errors, status: :unprocessable_entity } else + flash[:errors] = @crm_customers.errors format.html { redirect_to crm_customers_path} format.json { render json: @crm_customers.errors, status: :unprocessable_entity } end @@ -133,7 +141,7 @@ end memberaction = MembershipAction.find_by_membership_type("update_membership_customer") merchant_uid = memberaction.merchant_account_id.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - + response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, dob: dob, id: id,member_group_id:member_group_id,merchant_uid:merchant_uid}.to_json, @@ -148,7 +156,8 @@ end else - format.html { render :index } + flash[:errors] = @crm_customers.errors + format.html { redirect_to crm_customers_path} format.json { render json: @crm_customer.errors, status: :unprocessable_entity } end diff --git a/app/controllers/crm/home_controller.rb b/app/controllers/crm/home_controller.rb index d1ee475b..c05e7cf3 100644 --- a/app/controllers/crm/home_controller.rb +++ b/app/controllers/crm/home_controller.rb @@ -43,18 +43,18 @@ class Crm::HomeController < BaseCrmController end - def update_sale_by_customer + # def update_sale_by_customer - sale = Sale.find(params[:sale_id]) - status = sale.update_attributes(customer_id: params[:customer_id]) + # sale = Sale.find(params[:sale_id]) + # status = sale.update_attributes(customer_id: params[:customer_id]) - if status == true - render json: JSON.generate({:status => true}) - else - render json: JSON.generate({:status => false, :error_message => "Record not found"}) + # if status == true + # render json: JSON.generate({:status => true}) + # else + # render json: JSON.generate({:status => false, :error_message => "Record not found"}) - end - end + # end + # end end diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 14af5f49..7d0b5502 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -24,12 +24,10 @@ class Origami::CustomersController < BaseOrigamiController end # @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(2) @crm_customer = Customer.new - # @membership = Customer.get_member_group - # if @membership["status"] == true - # @member_group = @membership["data"] - # end - # puts "Errrrrrrrrrrrrrrrrr" - # puts @crm_customer.valid? + + if flash["errors"] + @crm_customer.valid? + end respond_to do |format| diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 134c9474..bdae0f0e 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -20,6 +20,31 @@ class Origami::PaymentsController < BaseOrigamiController @cash = 0.0 @other = 0.0 @sale_data = Sale.find_by_sale_id(sale_id) + + #get customer amount + @customer = Customer.find(@sale_data.customer_id) + + membership = MembershipSetting.find_by_membership_type("paypar_url") + + memberaction = MembershipAction.find_by_membership_type("get_all_member_account") + merchant_uid = memberaction.merchant_account_id.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + + response = HTTParty.get(url, :body => { membership_id: @customer.membership_id,merchant_uid:merchant_uid}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + } + ) + + @balance = 0.00 + response["data"].each do |res| + if res["accountable_type"] == "RebateAccount" + @balance = res["balance"] + end + end + #end customer amount + @sale_data.sale_payments.each do |spay| if spay.payment_method == "cash" @cash = spay.payment_amount diff --git a/app/controllers/origami/redeem_payments_controller.rb b/app/controllers/origami/redeem_payments_controller.rb index 5fd386e8..b68fd30a 100644 --- a/app/controllers/origami/redeem_payments_controller.rb +++ b/app/controllers/origami/redeem_payments_controller.rb @@ -4,6 +4,7 @@ class Origami::RedeemPaymentsController < BaseOrigamiController payment_method = params[:payment_method] @membership_rebate_balance=0 sale_data = Sale.find_by_sale_id(@sale_id) + @food_prices, @beverage_prices = SaleItem.calculate_food_beverage(sale_data.sale_items) if sale_data if sale_data.customer_id customer_data= Customer.find_by_customer_id(sale_data.customer_id) @@ -28,8 +29,8 @@ class Origami::RedeemPaymentsController < BaseOrigamiController else @out = false,0 end - - + + else @out = false, 0 end diff --git a/app/models/order.rb b/app/models/order.rb index c1dfec43..9a1afe5d 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -243,7 +243,7 @@ class Order < ApplicationRecord .joins("left join orders on orders.order_id = booking_orders.order_id") .joins("left join sales on sales.sale_id = bookings.sale_id") .where("sales.sale_status='completed'") - .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.order_id") end #Origami: Cashier : to view order type Room diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index ffe881e6..894592b5 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -84,17 +84,22 @@ class SalePayment < ApplicationRecord url = paypar_url.to_s + membership_actions_data.gateway_url.to_s merchant_uid = membership_actions_data.merchant_account_id campaign_type_id = membership_actions_data.additional_parameter["campaign_type_id"] - response = HTTParty.post(url, - :body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipet_no:sale_id,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid}.to_json, + sale_data = Sale.find_by_sale_id(sale_id) + if sale_data + response = HTTParty.post(url, + :body => { generic_customer_id:membership_id,redeem_amount:received_amount,receipt_no:sale_data.receipt_no,campaign_type_id:campaign_type_id,account_no:"",merchant_uid:merchant_uid}.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json' } ) + else + response = false; + end + else response =false; end - puts response.to_json return response; end @@ -236,7 +241,7 @@ class SalePayment < ApplicationRecord def rebat(sObj) food_prices, beverage_prices = SaleItem.calculate_food_beverage(sObj.sale_items) generic_customer_id = sObj.customer.membership_id - if generic_customer_id != nil || generic_customer_id != "" + if generic_customer_id != nil || generic_customer_id != "" || generic_customer_id != 0 paypar = sObj.sale_payments payparcost = 0 paypar.each do |pp| @@ -245,24 +250,22 @@ class SalePayment < ApplicationRecord end end total_amount = food_prices - payparcost - puts "aaaa" - puts food_prices - puts payparcost - puts total_amount - receipt_no = sObj.receipt_no - membership = MembershipSetting.find_by_membership_type("paypar_url") - memberaction = MembershipAction.find_by_membership_type("rebate") - campaign_type_id = memberaction.additional_parameter["campaign_type_id"] - app_token = membership.auth_token.to_s - url = membership.gateway_url.to_s + memberaction.gateway_url.to_s - response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,total_amount: total_amount,campaign_type_id: campaign_type_id, - receipt_no: receipt_no}.to_json, - :headers => { - 'Content-Type' => 'application/json', - 'Accept' => 'application/json' - }) + if total_amount > 0 + receipt_no = sObj.receipt_no + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("rebate") + campaign_type_id = memberaction.additional_parameter["campaign_type_id"] + app_token = membership.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + response = HTTParty.post(url, :body => { generic_customer_id:generic_customer_id ,total_amount: total_amount,campaign_type_id: campaign_type_id, + receipt_no: receipt_no}.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }) - puts response.to_json + puts response.to_json + end end end diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index 9f62b55b..d72c6a38 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -66,45 +66,47 @@ -
You can rebate upto <%= @food_prices %>