diff --git a/Gemfile b/Gemfile index 4c544ad6..5344bdc5 100644 --- a/Gemfile +++ b/Gemfile @@ -59,6 +59,7 @@ gem 'jbuilder', '~> 2.5' gem 'bcrypt', '~> 3.1.7' gem 'sidekiq' +gem 'whenever', :require => false # XML parser #gem 'nokogiri', '~> 1.6' diff --git a/Gemfile.lock b/Gemfile.lock index 7e27774a..affb7b95 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -51,6 +51,7 @@ GEM builder (3.2.3) byebug (9.0.6) cancancan (1.17.0) + chronic (0.10.2) coffee-rails (4.2.2) coffee-script (>= 2.2.0) railties (>= 4.0.0) @@ -237,6 +238,8 @@ GEM websocket-driver (0.6.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.2) + whenever (0.9.7) + chronic (>= 0.6.3) PLATFORMS ruby @@ -282,6 +285,7 @@ DEPENDENCIES tzinfo-data uglifier (>= 1.3.0) web-console (>= 3.3.0) + whenever BUNDLED WITH 1.15.1 diff --git a/app/controllers/crm/customers_controller.rb b/app/controllers/crm/customers_controller.rb index 81e7bb71..4606b049 100644 --- a/app/controllers/crm/customers_controller.rb +++ b/app/controllers/crm/customers_controller.rb @@ -48,7 +48,22 @@ class Crm::CustomersController < BaseCrmController #get customer amount @customer = Customer.find(params[:id]) - @response = Customer.get_membership_transactions(@customer) + @response = Customer.get_membership_transactions(@customer) + # get member information + total = Customer.get_member_account(@customer) + + + @balance = 0.00 + @accountable_type = '' + if total["status"]==true + total["data"].each do |res| + if res["accountable_type"] == "RebateAccount" || res["accountable_type"] == "RebatebonusAccount" + @balance += res["balance"] + # @accountable_type = res["accountable_type"] + @accountable_type = "Rebate Balance" + end + end + end # @response = "" #end customer amount @@ -127,7 +142,8 @@ class Crm::CustomersController < BaseCrmController end # format.json { render :index, status: :created, location: @crm_customers } else - # @crm_customers.destroy + customer = Customer.find(@crm_customers.customer_id) + status = customer.update_attributes(membership_type:member_group_id ) if params[:sale_id] format.html { redirect_to '/origami/'+params[:sale_id]+'/customers', notice: 'Customer was successfully created.' + response[:message]} else @@ -211,7 +227,12 @@ end 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 + + customer = Customer.find(@crm_customer.customer_id) + status = customer.update_attributes(membership_type:member_group_id ) + format.html { redirect_to crm_customers_path, notice: response["error"] } end diff --git a/app/controllers/origami/customers_controller.rb b/app/controllers/origami/customers_controller.rb index e8376fc4..203e5600 100644 --- a/app/controllers/origami/customers_controller.rb +++ b/app/controllers/origami/customers_controller.rb @@ -34,6 +34,7 @@ class Origami::CustomersController < BaseOrigamiController #@crm_customers = Customer.all @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? diff --git a/app/controllers/settings/order_queue_stations_controller.rb b/app/controllers/settings/order_queue_stations_controller.rb index 9fe78de4..dea66941 100644 --- a/app/controllers/settings/order_queue_stations_controller.rb +++ b/app/controllers/settings/order_queue_stations_controller.rb @@ -74,10 +74,10 @@ class Settings::OrderQueueStationsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def settings_order_queue_station_params # <<<<<<< HEAD - params.require(:order_queue_station).permit(:station_name, :is_active, :auto_print, :processing_items, :print_copy, :printer_name, :font_size, :cut_per_item, :use_alternate_name, :created_by) +# params.require(:order_queue_station).permit(:station_name, :is_active, :auto_print, :processing_items, :print_copy, :printer_name, :font_size, :cut_per_item, :use_alternate_name, :created_by) # ======= # Don't Know { zone_ids: [] } -# params.require(:order_queue_station).permit(:station_name, :is_active, :processing_items, :print_copy, :printer_name, :font_size, :cut_per_item, :use_alternate_name, :created_by,{ zone_ids: [] }) + params.require(:order_queue_station).permit(:station_name, :is_active, :processing_items, :print_copy, :printer_name, :font_size, :cut_per_item, :use_alternate_name, :created_by,{ zone_ids: [] }) # >>>>>>> b093a993ba002c92659bbb34338c55c031c11d87 end end diff --git a/app/models/customer.rb b/app/models/customer.rb index d6ba8bf1..60cf8b14 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -76,6 +76,48 @@ class Customer < ApplicationRecord end + def self.update_membership + membership = MembershipSetting.find_by_membership_type("paypar_url") + memberaction = MembershipAction.find_by_membership_type("create_membership_customer") + merchant_uid = memberaction.merchant_account_id.to_s + auth_token = memberaction.auth_token.to_s + url = membership.gateway_url.to_s + memberaction.gateway_url.to_s + + @customers = Customer.where("membership_type IS NOT NULL AND membership_id IS NULL") + + @customers.each do |customer| + begin + response = HTTParty.post(url, + :body => + { name: customer.name,phone: customer.contact_no, + email: customer.email,dob: customer.date_of_birth, + address: customer.address,nrc:customer.nrc_no, + card_no:customer.card_no,member_group_id: customer.membership_type, + merchant_uid:merchant_uid,auth_token:auth_token + }.to_json, + :headers => { + 'Content-Type' => 'application/json', + 'Accept' => 'application/json' + }) + rescue Net::OpenTimeout + response = { status: false } + + rescue OpenURI::HTTPError + response = { status: false} + + rescue SocketError + response = { status: false} + end + + puts response.to_json + + if response["status"] == true + status = customer.update_attributes(membership_id: response["customer_datas"]["id"]) + end + + end + end + def self.search(search) if search # find(:all, :conditions => ['name LIKE ? OR contact_no LIKE ?', "%#{search}%", "%#{search}%"]) diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 6f38d95f..fb1e58d8 100644 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -306,16 +306,22 @@ class SalePayment < ApplicationRecord if generic_customer_id != nil || generic_customer_id != "" || generic_customer_id != 0 paypar = sObj.sale_payments payparcost = 0 + credit = 0 paypar.each do |pp| if pp.payment_method == "paypar" payparcost = payparcost + pp.payment_amount + elsif pp.payment_method == "creditnote" + credit = 1 end end # overall_dis = SaleItem.get_overall_discount(sObj.id) overall_dis = sObj.total_discount total_amount = rebate_prices - payparcost - overall_dis - if total_amount > 0 + if credit == 1 + total_amount = 0 + end + if total_amount >= 0 receipt_no = sObj.receipt_no membership = MembershipSetting.find_by_membership_type("paypar_url") memberaction = MembershipAction.find_by_membership_type("rebate") diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index b3b29914..fc04b6cc 100644 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -168,7 +168,10 @@ class CloseCashierPdf < Prawn::Document text "#{shift_sale.grand_total}", :size => self.item_font_size, :align => :right end + move_down 5 + stroke_horizontal_rule move_down 5 + move_down 5 end diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index 60e1203c..52cdf586 100644 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -233,9 +233,16 @@ class ReceiptBillPdf < Prawn::Document SalePayment.where('sale_id = ?', sale_data.sale_id).each do |payment| y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + if payment.payment_method == "paypar" + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Redeem Payment", :size => self.item_font_size,:align => :left + end + else + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do text "#{payment.payment_method.capitalize} Payment", :size => self.item_font_size,:align => :left end + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{number_with_precision(payment.payment_amount, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right end @@ -263,34 +270,56 @@ class ReceiptBillPdf < Prawn::Document if rebate_amount["status"] == true stroke_horizontal_rule rebate = 0 + redeem = 0 rebate_amount["data"].each do |res| - if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Rebate" - - rebate = rebate + res["rebate"] - - end if res["receipt_no"]== sale_data.receipt_no && res["status"]== "Redeem" - - move_down 5 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Current Redeem Amount", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(res["redeem"], :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right - end + redeem = redeem + res["redeem"] + end + + + if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebateAccount" && res["status"]== "Rebate" + + rebate = rebate + res["rebate"] + + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Rebate Earn", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(res["balance"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + + end + + if res["receipt_no"]== sale_data.receipt_no && res["account_status"]== "RebateBonusAccount" && res["status"]== "Rebate" + + rebate = rebate + res["rebate"] + + move_down 5 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Rebate Earn Bonus", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(res["balance"], :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right + end + + end end + move_down 5 - y_position = cursor - bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Current Rebate Amount", :size => self.item_font_size,:align => :left - end - bounding_box([self.item_description_width,y_position], :width =>self.label_width) do - text "#{number_with_precision(rebate, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right - end + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Redeem Amount", :size => self.item_font_size,:align => :left + end + bounding_box([self.item_description_width,y_position], :width =>self.label_width) do + text "#{number_with_precision(redeem, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size,:align => :right + end + end end if member_info["status"] == true && member_info["data"].present? @@ -306,7 +335,7 @@ class ReceiptBillPdf < Prawn::Document move_down 5 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => self.item_height) do - text "Current Balance", :size => self.item_font_size,:align => :left + text "Total Balance", :size => self.item_font_size,:align => :left end bounding_box([self.item_description_width,y_position], :width =>self.label_width) do text "#{number_with_precision(balance, :precision => precision.to_i, :delimiter => delimiter)}" , :size => self.item_font_size,:align => :right @@ -364,10 +393,10 @@ class ReceiptBillPdf < Prawn::Document y_position = cursor bounding_box([0, y_position], :width =>self.label_width, :height => self.item_height) do - text "#{printed_status}", :size => self.header_font_size,:align => :left + text "#{printed_status}", :size => self.item_font_size,:align => :left end - bounding_box([self.label_width,y_position], :width =>self.label_width, :height => self.item_height) do - text "Thank You! See you Again", :left_margin => -10, :size => self.header_font_size,:align => :right + bounding_box([self.item_description_width,y_position], :width =>self.item_description_width, :height => self.item_height) do + text "Thank You! See you Again", :left_margin => -10, :size => self.item_font_size,:align => :left end move_down 5 diff --git a/app/views/crm/customers/index.html.erb b/app/views/crm/customers/index.html.erb index b3c1fce7..a44aed2f 100644 --- a/app/views/crm/customers/index.html.erb +++ b/app/views/crm/customers/index.html.erb @@ -47,11 +47,15 @@ <% @i = 0 %> <% @crm_customers.each do |crm_customer| %> - <% if crm_customer.customer_id != "CUS-00001" && crm_customer.customer_id != "CUS-000000000" %> + - <%= @i += 1 %> + + <% if crm_customer.customer_id != "CUS-000000000001" && crm_customer.customer_id != "CUS-000000000002" %> + <%= @i += 1 %> + <% end %> + <%= crm_customer.name %> <%= crm_customer.card_no rescue '-' %> <%= crm_customer.contact_no %> @@ -59,7 +63,7 @@ <%= link_to 'Show', crm_customer_path(crm_customer) %> - <% end %> + <% end %> diff --git a/app/views/crm/customers/show.html.erb b/app/views/crm/customers/show.html.erb index 5d36f5c3..21a05d9c 100644 --- a/app/views/crm/customers/show.html.erb +++ b/app/views/crm/customers/show.html.erb @@ -32,6 +32,7 @@ NRC/Passport No Address DOB + Membership Type @@ -45,8 +46,16 @@ <%= @customer.nrc_no %> <%= @customer.address%> <%= @customer.date_of_birth %> + <% if @customer.membership_type.to_f > 0%> + <%lookup= Lookup.find_by_value(@customer.membership_type) %> + <%= lookup.name %> + + <%else%> + - + <%end%> + - + @@ -55,21 +64,19 @@
- <% - if @response["data"].present? %> + - <% if @response["status"] == true %> - - <% end %> + + + - <% end %> - + @@ -82,7 +89,7 @@ - + diff --git a/app/views/origami/customers/index.html.erb b/app/views/origami/customers/index.html.erb index 489487ab..72e402e8 100644 --- a/app/views/origami/customers/index.html.erb +++ b/app/views/origami/customers/index.html.erb @@ -41,11 +41,15 @@ <% if @crm_customers.count > 0 %> <% @i = 0 %> <% @crm_customers.each do |crm_customer| %> - <% if crm_customer.customer_id != "CUS-00000" && crm_customer.customer_id != "CUS-00000000" %> + - + @@ -53,7 +57,6 @@ - <% end %> <% end %> <%else%> @@ -155,10 +158,10 @@ <%= f.input :address, :class => "form-control col-md-6 address" %> - +
<%= f.text_field :date_of_birth,:value=>"01-01-1990",:class=>"form-control datepicker"%> diff --git a/app/views/transactions/sales/show.html.erb b/app/views/transactions/sales/show.html.erb index b62289b1..4dd15755 100644 --- a/app/views/transactions/sales/show.html.erb +++ b/app/views/transactions/sales/show.html.erb @@ -39,6 +39,9 @@ + @@ -235,23 +238,31 @@
+
+
+
+
Membership TransactionsCurrent Balance : <%= @response["data"].last["balance"]%>Current Balance : <%= @balance%>
Date Redeem Rebate BalanceFrom Account Status Receipt No
<%= transaction["redeem"]%> <%= transaction["rebate"] %> <%= transaction["balance"] %><%= transaction["account_status"] %> <%= transaction["status"] %> <%= transaction["receipt_no"] %>
<%= @i += 1 %> + <% if crm_customer.customer_id != "CUS-000000000001" && crm_customer.customer_id != "CUS-000000000002" %> + <%= @i += 1 %> + <% end %> + <%= crm_customer.name %> <%= crm_customer.company rescue '-' %> <%= crm_customer.contact_no %>

There are no record for your search

+ + + + + + + + + + + + + +
StatusAction AtApproved ByRemark
+
+ + - diff --git a/config/schedule.rb b/config/schedule.rb new file mode 100644 index 00000000..b21a46e3 --- /dev/null +++ b/config/schedule.rb @@ -0,0 +1,7 @@ +set :environment, "development" +env :PATH, ENV['PATH'] +set :output, 'log/whenever.log' + +every 30.minutes do + runner "Customer.update_membership" +end \ No newline at end of file diff --git a/db/seeds.rb b/db/seeds.rb index b71418a9..3bff75a0 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -159,6 +159,7 @@ admin_employee = Employee.create({name: "Cashier", role: "cashier", password: "3 order_station1=PrintSetting.create({name: "OrderItemPdf", unique_code: "OrderItemPdf", printer_name: "Cashier", precision: "0", delimiter: "0", heading_space: "5"}) order_station2=PrintSetting.create({name: "Order Summary", unique_code: "OrderSummaryPdf", printer_name: "Cashier", precision: "0", delimiter: "0", heading_space: "5"}) request_bill_printer=PrintSetting.create({name: "Receipt Bill", unique_code: "ReceiptBillPdf", printer_name: "Cashier", precision: "0", delimiter: "0", heading_space: "5"}) +close_cashier_printer=PrintSetting.create({name: "Close Cashier", unique_code: "CloseCashierPdf", printer_name: "Cashier", precision: "0", delimiter: "0", heading_space: "5"}) crm_order_printer=PrintSetting.create({name: "CRM Order", unique_code: "CrmOrderPdf", printer_name: "Cashier", precision: "0", delimiter: "0", heading_space: "5"}) queue_no_printer=PrintSetting.create({name: "Queue No", unique_code: "QueueNoPdf", printer_name: "Cashier", precision: "0", delimiter: "0", heading_space: "5"}) diff --git a/lib/tasks/menu_import.rake b/lib/tasks/menu_import.rake index 8ec45d42..508f665f 100644 --- a/lib/tasks/menu_import.rake +++ b/lib/tasks/menu_import.rake @@ -67,7 +67,9 @@ menu_category3 = MenuCategory.create({menu: menu, code:"C003", name: "Beef & Mut menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Half Potion",item_instance_code:"II0152", menu_item: menu_category1_menu_item7, price:8000.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Full Potion",item_instance_code:"II0151", menu_item: menu_category1_menu_item7, price:16000.00, is_on_promotion:false}]) # Sliced Beef (Thin) - menu_category1_menu_item8 = SimpleMenuItem.create({item_code:"01009", name: "Sliced Beef (Thin)", alt_name: "精选牛肉片 (薄片)",menu_category: menu_category3 , min_selectable_item: 1, max_selectable_item:1, account: food }) + + menu_category1_menu_item8 = SimpleMenuItem.create({item_code:"01009", name: "Sliced Beef ( Thin )", alt_name: "精选牛肉片 ( 薄片 ) ",menu_category: menu_category3 , min_selectable_item: 1, max_selectable_item:1, account: food }) + menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Half Potion",item_instance_code:"II0162", menu_item: menu_category1_menu_item8, price:6000.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Full Potion",item_instance_code:"II0161", menu_item: menu_category1_menu_item8, price:12000.00, is_on_promotion:false}]) # Tender Sliced Beef @@ -87,7 +89,7 @@ menu_category3 = MenuCategory.create({menu: menu, code:"C003", name: "Beef & Mut menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Half Potion",item_instance_code:"II0202", menu_item: menu_category1_menu_item12, price:7000.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Full Potion",item_instance_code:"II0201", menu_item: menu_category1_menu_item12, price:14000.00, is_on_promotion:false}]) # Sliced Beef ( Think ) - menu_category1_menu_item13 = SimpleMenuItem.create({item_code:"01014", name: "Sliced Beef ( Think )", alt_name: "Twin Pot",menu_category: menu_category3 , min_selectable_item: 1, max_selectable_item:1, account: food }) + menu_category1_menu_item13 = SimpleMenuItem.create({item_code:"01014", name: "Sliced Beef ( Thick )", alt_name: "Twin Pot",menu_category: menu_category3 , min_selectable_item: 1, max_selectable_item:1, account: food }) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Half Potion",item_instance_code:"II1432", menu_item: menu_category1_menu_item13, price:7000.00, is_on_promotion:false}]) menu_item0_instance = MenuItemInstance.create([{item_instance_name:"Full Potion",item_instance_code:"II1431", menu_item: menu_category1_menu_item13, price:14000.00, is_on_promotion:false}]) # Pork