From 33cb8b64a32d25c093bf89cb44d545999adaf26f Mon Sep 17 00:00:00 2001 From: Aung Myo Date: Tue, 20 Jun 2017 17:57:50 +0630 Subject: [PATCH] finished customer form and update --- app/assets/stylesheets/CRM.scss | 3 + app/controllers/crm/customers_controller.rb | 33 +++--- .../origami/payments_controller.rb | 5 +- app/models/customer.rb | 42 ++----- app/models/sale_payment.rb | 4 +- app/views/api/customers/index.json.jbuilder | 4 +- app/views/api/customers/show.json.jbuilder | 4 +- app/views/crm/customers/index.html.erb | 107 +++++++++++++++--- app/views/crm/customers/show.json.jbuilder | 5 +- app/views/origami/customers/index.html.erb | 93 +++++++++++++-- app/views/reports/receipt_no/index.html.erb | 9 +- app/views/transactions/sales/show.html.erb | 2 +- ....rb => 20170620091919_create_customers.rb} | 8 +- 13 files changed, 235 insertions(+), 84 deletions(-) rename db/migrate/{20170403135121_create_customers.rb => 20170620091919_create_customers.rb} (73%) diff --git a/app/assets/stylesheets/CRM.scss b/app/assets/stylesheets/CRM.scss index 8ddc1605..e2b88eaa 100644 --- a/app/assets/stylesheets/CRM.scss +++ b/app/assets/stylesheets/CRM.scss @@ -23,3 +23,6 @@ .assign .text-muted{ color: #fff !important; } +.required abbr{ + color: red !important; +} \ No newline at end of file diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index d83d434f..0adefbf4 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -7,23 +7,19 @@ class Crm::CustomersController < BaseCrmController filter = params[:filter] if filter.nil? - @crm_customers = Customer.order("customer_id").page(params[:page]) - #@products = Product.order("name").page(params[:page]).per(5) + @crm_customers = Customer.all else @crm_customers = Customer.search(filter) end #@crm_customers = Customer.all - @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) + @crm_customers = Kaminari.paginate_array(@crm_customers).page(params[:page]).per(50) @crm_customer = Customer.new + @count_customer = Customer.count_customer # if flash["errors"] # @crm_customer.valid? # end - # @membership = Customer.get_member_group - # if @membership["status"] == true - # @member_group = @membership["data"] - # end respond_to do |format| format.html # index.html.erb format.json { render json: @crm_customers } @@ -50,14 +46,14 @@ class Crm::CustomersController < BaseCrmController end #get customer amount - @customer = Customer.find(params[:id]) - response = Customer.get_member_account(@customer) + # @customer = Customer.find(params[:id]) + # response = Customer.get_member_account(@customer) - if(response["status"] == true) - @membership = response["data"] - else + # if(response["status"] == true) + # @membership = response["data"] + # else @membership = 0 - end + # end #end customer amount @@ -87,6 +83,8 @@ class Crm::CustomersController < BaseCrmController phone = customer_params[:contact_no] email = customer_params[:email] dob = customer_params[:date_of_birth] + address = customer_params[:address] + nrc = customer_params[:nrc_no] member_group_id = params[:member_group_id] membership = MembershipSetting.find_by_membership_type("paypar_url") @@ -97,7 +95,7 @@ class Crm::CustomersController < BaseCrmController begin response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, - dob: dob, + dob: dob,address: address,nrc:nrc, member_group_id: member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', @@ -155,6 +153,8 @@ end phone = customer_params[:contact_no] email = customer_params[:email] dob = customer_params[:date_of_birth] + address = customer_params[:address] + nrc = customer_params[:nrc_no] id = @crm_customer.membership_id member_group_id = params[:member_group_id] @@ -165,7 +165,7 @@ end url = membership.gateway_url.to_s + memberaction.gateway_url.to_s begin response = HTTParty.post(url, :body => { name: name,phone: phone,email: email, - dob: dob, + dob: dob,address: address,nrc:nrc, id: id,member_group_id:member_group_id,merchant_uid:merchant_uid,auth_token:auth_token}.to_json, :headers => { 'Content-Type' => 'application/json', @@ -207,6 +207,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, :date_of_birth) + params.require(:customer).permit(:name, :company, :contact_no, :email, + :date_of_birth,:salution,:gender,:nrc_no,:address,:card_no) end end diff --git a/app/controllers/origami/payments_controller.rb b/app/controllers/origami/payments_controller.rb index e8ce6a96..6a6f4ca6 100644 --- a/app/controllers/origami/payments_controller.rb +++ b/app/controllers/origami/payments_controller.rb @@ -10,10 +10,9 @@ class Origami::PaymentsController < BaseOrigamiController if(Sale.exists?(sale_id)) saleObj = Sale.find(sale_id) sale_payment = SalePayment.new - rebate_amount = sale_payment.process_payment(saleObj, @user, cash, "cash") + sale_payment.process_payment(saleObj, @user, cash, "cash") - puts "resssssssssssssssssss" - puts rebate_amount.to_json + rebate_amount = nil unique_code = "ReceiptBillPdf" customer= Customer.find(saleObj.customer_id) diff --git a/app/models/customer.rb b/app/models/customer.rb index de9846f2..0924d232 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -45,43 +45,19 @@ class Customer < ApplicationRecord end end -# require "net/http" -# def self.url_exist?(url_string) -# url = URI.parse(url_string) - - -# req = Net::HTTP.new(url.host, url.port) -# puts "hhhhhhhhhhhh" -# puts req.to_json -# req.use_ssl = (url.scheme == 'https') -# puts "aaaaaaaaaaaa" -# puts req.use_ssl? -# path = url.path if url.path.present? -# puts "bbbbbbbbbbbbb" -# puts path -# res = req.request_head(path || '/') -# puts "cccccccccccccc" -# puts res.to_json -# puts "ddddddddd" -# puts res.kind_of?(Net::HTTPRedirection) -# if res.kind_of?(Net::HTTPRedirection) -# url_exist?(res['location']) # Go after any redirect and make sure you can access the redirected URL -# else -# ! %W(4 5).include?(res.code[0]) # Not from 4xx or 5xx families -# end -# rescue Errno::ENOENT -# false #false if can't find the server -# end - - - # def self.search(search) - # where("name LIKE ? OR contact_no LIKE ?", "%#{search}%", "%#{search}%",) - # end - def lastest_invoices sales.where(:customer_id => self.id).order("created_at desc").limit(5) end + def self.count_customer + all = self.all.count+1 + count = all-2 + + end + + WALKIN = "CUS-000000000001" + TAKEAWAY = "CUS-000000000002" + private def generate_custom_id self.customer_id = SeedGenerator.generate_id(self.class.name, "CUS") diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 92bebd59..c31ed341 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -54,10 +54,8 @@ class SalePayment < ApplicationRecord #record an payment in sale-audit remark = "Payment #{payment_method}- for Invoice #{invoice.receipt_no} Due [#{amount_due}]| pay amount -> #{cash_amount} | Payment Status ->#{payment_status}" sale_audit = SaleAudit.record_payment(invoice.id, remark, action_by) - sObj = Sale.find(self.sale_id) - response = rebat(sObj) - return true, response + return true, self.save else #record an payment in sale-audit remark = "No outstanding Amount - Grand Total [#{invoice.grand_total}] | Due [#{amount_due}] | Paid [#{invoice.amount_received}]" diff --git a/app/views/api/customers/index.json.jbuilder b/app/views/api/customers/index.json.jbuilder index 900e6c6b..2c3c07a7 100644 --- a/app/views/api/customers/index.json.jbuilder +++ b/app/views/api/customers/index.json.jbuilder @@ -1 +1,3 @@ -json.array! @customers, :id, :name, :company, :contact_no, :email, :membership_id, :membership_type +json.array! @customers, :id, :name, :company, :contact_no,:salution, + :gender,:nrc_no,:address,:card_no, :membership_type, + :membership_id, :created_at diff --git a/app/views/api/customers/show.json.jbuilder b/app/views/api/customers/show.json.jbuilder index 79397308..db56961b 100644 --- a/app/views/api/customers/show.json.jbuilder +++ b/app/views/api/customers/show.json.jbuilder @@ -1,4 +1,6 @@ -json.extract! @customer, :id, :name, :company, :contact_no, :membership_type, :membership_id, :created_at +json.extract! @customer, :id, :name, :company, :contact_no,:salution, + :gender,:nrc_no,:address,:card_no, :membership_type, + :membership_id, :created_at json.invoices do json.array! @customer.lastest_invoices ,:id, :receipt_no, :receipt_date, :sale_status, :payment_status end diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index f97de091..532857f9 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -34,6 +34,7 @@ Select + Sr.no Name Company Contact no @@ -43,11 +44,13 @@ <% if @crm_customers.count > 0 %> + <% @i = 0 %> <% @crm_customers.each do |crm_customer| %> <% if crm_customer.customer_id != "CUS-000000000001" && crm_customer.customer_id != "CUS-000000000002" %> + <%= @i += 1 %> <%= crm_customer.name %> <%= crm_customer.company rescue '-' %> <%= crm_customer.contact_no %> @@ -75,32 +78,89 @@ <%= f.hidden_field :id, :class => "form-control col-md-6 " %> + +
+
+ + + + +
"> - <%= f.input :name, :class => "form-control col-md-6 name" %> + <%= f.input :name, :class => "form-control col-md-6 name", :required => true %> + <% flash.each do |name, msg| %> - <%= msg['name'] %> + <% str="[\"#{msg['name']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> <% end -%> -
+
- <%= f.input :company, :class => "form-control col-md-6 company" %> +
+ + +
+ +
+ <%= f.input :nrc_no, :class => "form-control nrc_no" %> +
+ +
+ <%= f.input :company, :class => "form-control col-md-6 company",:required => true%> + + <% flash.each do |name, msg| %> + <% str="[\"#{msg['company']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> + <% end -%>
"> - <%= f.input :contact_no, :class => "form-control col-md-6 contact_no" %> + <%= f.input :contact_no, :class => "form-control col-md-6 contact_no" ,:required => true%> + <% flash.each do |name, msg| %> - <%= msg['contact_no'] %> + <% str="[\"#{msg['contact_no']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> <% end -%>
"> - <%= f.input :email, :class => "form-control col-md-6 email" %> + <%= f.input :email, :class => "form-control col-md-6 email" ,:required => true%> <% flash.each do |name, msg| %> - <%= msg['email'] %> + <% str="[\"#{msg['contact_no']}\"]" + str.gsub!('["', '') + str.gsub!('"]', '') %> + <%= str %> <% end -%>
+
+ <%= f.input :address, :class => "form-control col-md-6 address" %> +
+ +
+ + +
+
<%= f.text_field :date_of_birth,:value=>"01-01-1990",:class=>"form-control datepicker"%> @@ -137,12 +197,12 @@