From b14f4d67a5a5def04a397164332db3dd82cc2add Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 12 Jun 2017 18:23:12 +0630 Subject: [PATCH 1/7] origamijs --- app/assets/javascripts/origami.js | 14 ++++++++++---- app/controllers/crm/customers_controller.rb | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/origami.js b/app/assets/javascripts/origami.js index 45c6d909..b3872b84 100644 --- a/app/assets/javascripts/origami.js +++ b/app/assets/javascripts/origami.js @@ -188,11 +188,17 @@ $(document).ready(function(){ function show_customer_details(customer_id){ + if(window.location.pathname.substring(0, 12) == "/origami/SAL"){ + var url = customer_id+"/get_customer/" + }else{ + var url = "origami/"+customer_id+"/get_customer/" + } + $('.customer_detail').removeClass('hide'); //Start Ajax $.ajax({ type: "GET", - url: "origami/"+customer_id+"/get_customer/", + url: url, data: {}, dataType: "json", success: function(data) { @@ -201,10 +207,10 @@ $(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) { - $("#customer_amount").text(balance); + if (balance == "0.0") { + $("#customer_amount").text('0.0'); }else{ - $("#customer_amount").text('00'); + $("#customer_amount").text(balance); } diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 01acd441..c33db2e1 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -124,14 +124,14 @@ end phone = customer_params[:contact_no] email = customer_params[:email] date_of_birth = customer_params[:date_of_birth] - id = customer_params[:membership_id] + id = @crm_customer.membership_id member_group_id = params[:member_group_id] membership = MembershipSetting.find_by_membership_type("paypar_url") 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, date_of_birth: date_of_birth, id: id,member_group_id:member_group_id,merchant_uid:merchant_uid}.to_json, From 967d0350979abba96f8703db144cb92d70dc10d1 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 12 Jun 2017 18:31:42 +0630 Subject: [PATCH 2/7] change dob --- app/controllers/crm/customers_controller.rb | 8 ++++---- app/controllers/origami/customers_controller.rb | 3 --- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index c33db2e1..525302c8 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -63,7 +63,7 @@ class Crm::CustomersController < BaseCrmController name = customer_params[:name] phone = customer_params[:contact_no] email = customer_params[:email] - date_of_birth = customer_params[:date_of_birth] + dob = customer_params[:date_of_birth] member_group_id = params[:member_group_id] membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -72,7 +72,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, - date_of_birth: date_of_birth, + dob: dob, member_group_id: member_group_id,merchant_uid:merchant_uid}.to_json, :headers => { 'Content-Type' => 'application/json', @@ -123,7 +123,7 @@ end name = customer_params[:name] phone = customer_params[:contact_no] email = customer_params[:email] - date_of_birth = customer_params[:date_of_birth] + dob = customer_params[:date_of_birth] id = @crm_customer.membership_id member_group_id = params[:member_group_id] @@ -133,7 +133,7 @@ end url = membership.gateway_url.to_s + memberaction.gateway_url.to_s response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, - date_of_birth: date_of_birth, + dob: dob, id: id,member_group_id:member_group_id,merchant_uid:merchant_uid}.to_json, :headers => { 'Content-Type' => 'application/json', diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index a1a067fe..30ead5b0 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -28,9 +28,6 @@ class Origami::CustomersController < BaseOrigamiController # if @membership["status"] == true # @member_group = @membership["data"] # end - puts "Errrrrrrrrrrrrrrrrr" - puts @crm_customer.new_record? - respond_to do |format| # format.html { render :template => "crm/customers/index" } From 92f1f80acb0167790919c28d90c1384f0f4800e8 Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Mon, 12 Jun 2017 18:50:06 +0630 Subject: [PATCH 3/7] Edit Customer --- app/controllers/origami/customers_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index 30ead5b0..14af5f49 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -28,6 +28,9 @@ class Origami::CustomersController < BaseOrigamiController # if @membership["status"] == true # @member_group = @membership["data"] # end + # puts "Errrrrrrrrrrrrrrrrr" + # puts @crm_customer.valid? + respond_to do |format| # format.html { render :template => "crm/customers/index" } From 6945449523d0247d159cf0f8a24fb274d631bd93 Mon Sep 17 00:00:00 2001 From: Nweni Date: Mon, 12 Jun 2017 18:51:02 +0630 Subject: [PATCH 4/7] get update --- Gemfile | 2 +- Gemfile.lock | 2 ++ app/controllers/crm/customers_controller.rb | 18 +++++++------- app/models/order.rb | 27 ++++++++++----------- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Gemfile b/Gemfile index b08df141..02dca6af 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ gem 'rails', '~> 5.1.0' gem 'mysql2', '>= 0.3.18', '< 0.5' #Use PosgreSQL -# gem 'pg' +gem 'pg' # redis server for cable # gem 'redis', '~> 3.0' diff --git a/Gemfile.lock b/Gemfile.lock index 6a7c6340..4235d035 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,6 +110,7 @@ GEM nokogiri (1.7.2) mini_portile2 (~> 2.1.0) pdf-core (0.7.0) + pg (0.20.0) prawn (2.2.2) pdf-core (~> 0.7.0) ttfunk (~> 1.5) @@ -246,6 +247,7 @@ DEPENDENCIES kaminari (~> 0.16.3) listen (~> 3.0.5) mysql2 (>= 0.3.18, < 0.5) + pg prawn prawn-table puma (~> 3.0) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 01acd441..ad3bcc50 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -5,7 +5,7 @@ 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) @@ -31,7 +31,7 @@ class Crm::CustomersController < BaseCrmController # GET /crm/customers/1.json def show @orders = Order.where("customer_id=?", params[:id]) - + if @orders @order_items = [] @orders.each do |bo| @@ -57,7 +57,7 @@ class Crm::CustomersController < BaseCrmController def create @crm_customers = Customer.new(customer_params) - + respond_to do |format| if @crm_customers.save name = customer_params[:name] @@ -72,7 +72,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, - date_of_birth: date_of_birth, + dob: date_of_birth, member_group_id: member_group_id,merchant_uid:merchant_uid}.to_json, :headers => { 'Content-Type' => 'application/json', @@ -81,18 +81,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'} @@ -103,7 +103,7 @@ class Crm::CustomersController < BaseCrmController else if params[:sale_id] - format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} + format.html { redirect_to '/origami/'+params[:sale_id]+'/add_customer'} else format.html { redirect_to crm_customers_path} format.json { render json: @crm_customers.errors, status: :unprocessable_entity } diff --git a/app/models/order.rb b/app/models/order.rb index 5a4d6e2d..20d9a7f0 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -244,21 +244,20 @@ 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'") -<<<<<<< HEAD - .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status") + .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 booking order Table - def self.get_booking_order_table - booking_orders = Booking.select("sales.receipt_no,orders.status as order_status, - bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") - .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") - .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id") - .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' and booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true) - .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.customer_id,sales.customer_id,orders.order_id") - end + # #Origami: Cashier : to view booking order Table + # def self.get_booking_order_table + # booking_orders = Booking.select("sales.receipt_no,orders.status as order_status, + # bookings.booking_id,sales.sale_id as sale_id,dining_facilities.name as table_name") + # .joins("left join booking_orders on booking_orders.booking_id = bookings.booking_id") + # .joins("left join dining_facilities on dining_facilities.id = bookings.dining_facility_id") + # .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' and booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::TABLE_TYPE,true) + # .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.status,orders.customer_id,sales.customer_id,orders.order_id") + # end #Origami: Cashier : to view order type Room def self.get_booking_order_rooms @@ -272,7 +271,7 @@ class Order < ApplicationRecord .joins("left join sale_orders on sale_orders.order_id = orders.order_id") .joins("left join sales on sales.sale_id = sale_orders.sale_id") .where("sales.sale_status<>'completed' and sales.sale_status<>'complete' and booking_orders.order_id IS NOT NULL and dining_facilities.type=? and dining_facilities.is_active=?",DiningFacility::ROOM_TYPE,true) - .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id") + .group("bookings.booking_id,sales.receipt_no,orders.status,sales.sale_id,dining_facilities.name,orders.customer_id,orders.order_id") end #Origami: Cashier : to view order type Room From 796d511f2e659477be65fcd65c5a048382cf77ae Mon Sep 17 00:00:00 2001 From: Phyo Date: Mon, 12 Jun 2017 19:02:20 +0630 Subject: [PATCH 5/7] Rebate add --- app/models/sale_payment.rb | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index b8c527af..1acd8b57 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -60,7 +60,7 @@ class SalePayment < ApplicationRecord #record an payment in sale-audit remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" sale_audit = SaleAudit.record_payment(invoice.id, remark,action_by) - + return false, "No outstanding Amount" end @@ -217,7 +217,7 @@ class SalePayment < ApplicationRecord self.sale.sale_status = "completed" self.sale.save! table_update_status(sObj) - rebat() + rebat(sObj) end end @@ -233,8 +233,25 @@ class SalePayment < ApplicationRecord end end - def rebat + def rebat(sObj) + food_prices, beverage_prices = SaleItem.calculate_food_beverage(sObj.sale_items) + generic_customer_id = sObj.customer.membership_id + total_amount = sObj.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 + puts url + 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 end private From 4bbf65104084e6205d375c11fb4b567e22d27047 Mon Sep 17 00:00:00 2001 From: Phyo Date: Mon, 12 Jun 2017 19:31:01 +0630 Subject: [PATCH 6/7] Rebate Bug Fix --- app/models/sale_payment.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 1acd8b57..04668575 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -236,14 +236,13 @@ class SalePayment < ApplicationRecord def rebat(sObj) food_prices, beverage_prices = SaleItem.calculate_food_beverage(sObj.sale_items) generic_customer_id = sObj.customer.membership_id - total_amount = sObj.total_amount + total_amount = food_prices 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 - puts url 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 => { From c904451110a0697b50ba4e6622f9c5df96677a3b Mon Sep 17 00:00:00 2001 From: Nweni Date: Mon, 12 Jun 2017 19:35:05 +0630 Subject: [PATCH 7/7] update --- app/controllers/api/bill_controller.rb | 12 +++++++++--- app/controllers/origami/payments_controller.rb | 4 ++-- db/seeds.rb | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/api/bill_controller.rb b/app/controllers/api/bill_controller.rb index 193a4a45..a01cc717 100644 --- a/app/controllers/api/bill_controller.rb +++ b/app/controllers/api/bill_controller.rb @@ -8,9 +8,15 @@ class Api::BillController < Api::ApiController #create Bill by Booking ID if (params[:booking_id]) - @sale = Sale.new - @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee.name) - + booking = Booking.find(params[:booking_id]) + if booking + if booking.sale_id.nil? + @sale = Sale.new + @status, @sale_id = @sale.generate_invoice_from_booking(params[:booking_id], current_login_employee.name) + else + @status = true + end + end elsif (params[:order_id]) @sale = Sale.new @status, @sale_id = @sale.generate_invoice_from_order(params[:order_id], current_login_employee.name) diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index 290a2911..134c9474 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -24,8 +24,8 @@ class Origami::PaymentsController < BaseOrigamiController if spay.payment_method == "cash" @cash = spay.payment_amount end - if spay.payment_method == "mpu" - @other = spay.payment_amount + if spay.payment_method == "mpu" || spay.payment_method == "paypar" + @other += spay.payment_amount end end end diff --git a/db/seeds.rb b/db/seeds.rb index 28cbe535..c802079f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -157,7 +157,7 @@ member_actions= MembershipAction.create([{membership_type:"get_account_balance", ]) payment_methods = PaymentMethodSetting.create({payment_method:"MPU",gateway_url: "http//192.168.1.47:3006"}) -payment_methods = PaymentMethodSetting.create({payment_method:"JCB",gateway_url: "http//192.168.1.47:3006"}) + payment_methods = PaymentMethodSetting.create({payment_method:"REDEEMREBATE",gateway_url: "http://192.168.1.47:3006",merchant_account_id:"vWSsseoZCzxd6xcNf_uS"})