From 959102b338e12e3977235c3943aa29606040bc19 Mon Sep 17 00:00:00 2001 From: Nweni Date: Fri, 30 Jun 2017 09:49:51 +0630 Subject: [PATCH] Update --- app/controllers/crm/customers_controller.rb | 56 +++++++++++++------- app/controllers/origami/shifts_controller.rb | 1 + app/models/customer.rb | 12 +++++ app/models/sale_payment.rb | 18 +++++++ app/models/shift_sale.rb | 2 +- 5 files changed, 69 insertions(+), 20 deletions(-) diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index f2846c12..f8a80cb8 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -6,12 +6,12 @@ class Crm::CustomersController < BaseCrmController # GET /crm/customers.json def index filter = params[:filter] - + if filter.nil? @crm_customers = Customer.all else - @crm_customers = Customer.search(filter) - + @crm_customers = Customer.search(filter) + end #@crm_customers = Customer.all @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) @@ -32,7 +32,7 @@ class Crm::CustomersController < BaseCrmController def show @orders = Order.where("customer_id=?", params[:id]) @sales = Sale.where("customer_id=?", params[:id]) - + if @orders @order_items = [] @orders.each do |order| @@ -70,7 +70,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] @@ -81,7 +81,7 @@ class Crm::CustomersController < BaseCrmController nrc = customer_params[:nrc_no] card_no = customer_params[:card_no] member_group_id = params[:member_group_id] - + if !member_group_id.nil? membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("create_membership_customer") @@ -90,7 +90,7 @@ class Crm::CustomersController < BaseCrmController url = membership.gateway_url.to_s + memberaction.gateway_url.to_s begin - response = HTTParty.post(url, + response = HTTParty.post(url, :body => {name: name,phone: phone,email: email, dob: dob,address: address,nrc:nrc,card_no:card_no, member_group_id: member_group_id, @@ -103,18 +103,24 @@ class Crm::CustomersController < BaseCrmController ) rescue Net::OpenTimeout response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} end if response["status"] == true - + customer = Customer.find(@crm_customers.customer_id) status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) - + if params[:sale_id] format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', 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 @@ -129,7 +135,7 @@ class Crm::CustomersController < BaseCrmController if params[:sale_id] flash[:errors] = @crm_customers.errors - format.html { redirect_to '/origami/'+params[:sale_id]+'/customers'} + format.html { redirect_to '/origami/'+params[:sale_id]+'/customers'} format.json { render json: @crm_customers.errors, status: :unprocessable_entity } else flash[:errors] = @crm_customers.errors @@ -166,7 +172,7 @@ end url = membership.gateway_url.to_s + memberaction.gateway_url.to_s begin - response = HTTParty.post(url, + response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, dob: dob,address: address,nrc:nrc, card_no:card_no,member_group_id: member_group_id, @@ -176,16 +182,22 @@ end 'Accept' => 'application/json' }, :timeout => 10 - ) + ) rescue Net::OpenTimeout response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} end if response["status"] == true - + customer = Customer.find(@crm_customer.customer_id) status = customer.update_attributes(membership_id: response["customer_datas"]["id"],membership_type:member_group_id ) - + format.html { redirect_to crm_customers_path, notice: 'Customer was successfully updated'} else format.html { redirect_to crm_customers_path, notice: response["message"] } @@ -199,7 +211,7 @@ end auth_token = memberaction.auth_token.to_s url = membership.gateway_url.to_s + memberaction.gateway_url.to_s begin - response = HTTParty.post(url, + response = HTTParty.post(url, :body => {name: name,phone: phone,email: email, dob: dob,address: address,nrc:nrc,card_no:card_no, id: id,member_group_id:member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, @@ -211,6 +223,12 @@ end ) rescue Net::OpenTimeout response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} end if response["status"] == true @@ -219,8 +237,8 @@ end else format.html { redirect_to crm_customers_path, notice: response["message"] } end - - end + + end else @@ -251,7 +269,7 @@ end # Never trust parameters from the scary internet, only allow the white list through. def customer_params - params.require(:customer).permit(:name, :company, :contact_no, :email, + params.require(:customer).permit(:name, :company, :contact_no, :email, :date_of_birth,:salutation,:gender,:nrc_no,:address,:card_no) end end diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index cd607b42..079b9e80 100644 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -4,6 +4,7 @@ class Origami::ShiftsController < BaseOrigamiController end def show + puts current_user.id @shift = ShiftSale.current_open_shift(current_user.id) end diff --git a/app/models/customer.rb b/app/models/customer.rb index e6afca08..a26d857e 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -31,6 +31,12 @@ class Customer < ApplicationRecord ) rescue Net::OpenTimeout response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} end return response; @@ -55,6 +61,12 @@ class Customer < ApplicationRecord ) rescue Net::OpenTimeout response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} end return response; diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index feafd017..c78b6cd8 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -77,6 +77,12 @@ class SalePayment < ApplicationRecord ) rescue Net::OpenTimeout response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} end return response; end @@ -110,6 +116,12 @@ class SalePayment < ApplicationRecord ) rescue Net::OpenTimeout response = false + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} end else response = false; @@ -312,6 +324,12 @@ class SalePayment < ApplicationRecord }, :timeout => 10) rescue Net::OpenTimeout response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} end return response # puts response.to_json diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index d12c258b..5372864f 100644 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -21,7 +21,7 @@ class ShiftSale < ApplicationRecord #find open shift where is open today and is not closed and login by current cashier today_date = DateTime.now.strftime("%Y-%m-%d") puts today_date - shift = ShiftSale.where("DATE(shift_started_at)= #{ today_date } and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}").take + shift = ShiftSale.where("TO_CHAR(shift_started_at, 'YYYY-MM-DD')=? and shift_started_at is not null and shift_closed_at is null and employee_id = #{current_user}", today_date).take return shift #end