diff --git a/app/controllers/origami/home_controller.rb b/app/controllers/origami/home_controller.rb index 837f0c04..33d5a1d5 100755 --- a/app/controllers/origami/home_controller.rb +++ b/app/controllers/origami/home_controller.rb @@ -60,7 +60,9 @@ class Origami::HomeController < BaseOrigamiController @account_arr =[] accounts.each do |acc| account = TaxProfile.find(acc) - @account_arr.push(account) + if !account.nil? + @account_arr.push(account) + end end end end @@ -83,7 +85,9 @@ class Origami::HomeController < BaseOrigamiController @account_arr =[] accounts.each do |acc| account = TaxProfile.find(acc) - @account_arr.push(account) + if !account.nil? + @account_arr.push(account) + end end end @sale_taxes = [] diff --git a/app/controllers/origami/rooms_controller.rb b/app/controllers/origami/rooms_controller.rb index fe571c4e..b2319691 100755 --- a/app/controllers/origami/rooms_controller.rb +++ b/app/controllers/origami/rooms_controller.rb @@ -60,7 +60,9 @@ class Origami::RoomsController < BaseOrigamiController @account_arr =[] accounts.each do |acc| account = TaxProfile.find(acc) - @account_arr.push(account) + if !account.nil? + @account_arr.push(account) + end end end end @@ -83,7 +85,9 @@ class Origami::RoomsController < BaseOrigamiController @account_arr =[] accounts.each do |acc| account = TaxProfile.find(acc) - @account_arr.push(account) + if !account.nil? + @account_arr.push(account) + end end @sale_taxes = [] diff --git a/app/controllers/origami/shifts_controller.rb b/app/controllers/origami/shifts_controller.rb index 81d41565..52ac1571 100755 --- a/app/controllers/origami/shifts_controller.rb +++ b/app/controllers/origami/shifts_controller.rb @@ -96,12 +96,13 @@ class Origami::ShiftsController < BaseOrigamiController @total_dinein = ShiftSale.get_total_dinein(@shift).total_dinein_amount @total_takeway = ShiftSale.get_total_takeway(@shift).total_takeway_amount @total_other_charges = ShiftSale.get_total_other_charges(@shift).total_other_charges_amount - + @total_credit_payments = ShiftSale.get_shift_sales_with_credit_payment(shift_id).total_credit_payments + # get printer info print_settings = PrintSetting.find_by_unique_code(unique_code) printer = Printer::CashierStationPrinter.new(print_settings) - printer.print_close_cashier(print_settings,cashier_terminal,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile ) + printer.print_close_cashier(print_settings,cashier_terminal,@shift,shop_details,@sale_taxes,@other_payment,@total_amount_by_account,@total_discount_by_account,@total_member_discount,@total_dinein,@total_takeway,@total_other_charges,@total_waste,@total_spoile,@total_credit_payments) end end Employee.logout(session[:session_token]) diff --git a/app/models/printer/cashier_station_printer.rb b/app/models/printer/cashier_station_printer.rb index f6473df4..c83a161e 100755 --- a/app/models/printer/cashier_station_printer.rb +++ b/app/models/printer/cashier_station_printer.rb @@ -38,7 +38,7 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker # self.print(filename, cashier_terminal.printer_name) # end - def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile) + def print_close_cashier(printer_settings,cashier_terminal,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) #Use CUPS service #Generate PDF @@ -46,16 +46,16 @@ class Printer::CashierStationPrinter < Printer::PrinterWorker cashier = shift_sale.employee.name shift_name = shift_sale.shift_started_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") + "_" + shift_sale.shift_closed_at.utc.getlocal.strftime("%d-%m-%Y %I:%M %p") filename = "tmp/close_cashier_#{cashier}_#{shift_name}.pdf" - pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile) + pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) close_cashier_pdf = Lookup.collection_of("print_settings") #print_settings with name:CloseCashierPdf if !close_cashier_pdf.empty? close_cashier_pdf.each do |close_cashier| if close_cashier[0] == 'CloseCashierCustomisePdf' if close_cashier[1] == '1' - pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,@total_waste,@total_spoile) + pdf = CloseCashierCustomisePdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) else - pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile) + pdf = CloseCashierPdf.new(printer_settings,shift_sale,shop_details,sale_taxes,other_payment,amount,discount,member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) end end end diff --git a/app/models/sale_payment.rb b/app/models/sale_payment.rb index 170b4ce2..4a06337b 100755 --- a/app/models/sale_payment.rb +++ b/app/models/sale_payment.rb @@ -889,25 +889,26 @@ class SalePayment < ApplicationRecord end def get_credit_payment_left - query = SalePayment.select("(CASE WHEN (SUM(payment_amount) - (SELECT SUM(payment_amount) + sql = "SELECT SUM(payment_amount) from sale_payments join sale_audits on SUBSTRING_INDEX(remark,'||',1)=sale_payment_id - where sale_payments.sale_id = '#{self.sale_id}')) > 0 THEN (SUM(payment_amount) - (SELECT SUM(payment_amount) - from sale_payments - join sale_audits on SUBSTRING_INDEX(remark,'||',1)=sale_payment_id - where sale_payments.sale_id = '#{self.sale_id}')) ELSE 0 END) as payment_amount") + where sale_payments.sale_id = '#{self.sale_id}'" + + query = SalePayment.select("(CASE WHEN (SUM(payment_amount) - (#{sql})) > 0 THEN (SUM(payment_amount) - (#{sql})) ELSE 0 END) as payment_amount") .where("sale_payments.payment_method = 'creditnote' AND sale_payments.sale_id = '#{self.sale_id}'") return query end def self.get_sale_payments(sale_data) - query = sale_data.sale_payments - .where("CASE WHEN ((SELECT SUM(payment_amount) + sql = "SELECT SUM(payment_amount) FROM sale_payments where payment_method='creditnote' - and sale_id='#{sale_data.sale_id}') - - (SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) + and sale_id='#{sale_data.sale_id}'" + sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) FROM sale_payments where payment_method='creditnote' - and sale_id='#{sale_data.sale_id}') + and sale_id='#{sale_data.sale_id}'" + + query = sale_data.sale_payments + .where("CASE WHEN ((#{sql}) - (#{sql1}) ELSE SUM(payment_amount) END FROM sale_payments JOIN sales s ON s.sale_id=sale_payments.sale_id diff --git a/app/models/shift_sale.rb b/app/models/shift_sale.rb index 77adf0bd..18e20322 100755 --- a/app/models/shift_sale.rb +++ b/app/models/shift_sale.rb @@ -178,4 +178,11 @@ class ShiftSale < ApplicationRecord end + def self.get_shift_sales_with_credit_payment(shift_id) + query = SalePayment.select("(CASE WHEN SUM(sale_payments.payment_amount) > 0 THEN SUM(sale_payments.payment_amount) ELSE 0 END) as total_credit_payments") + .joins(" JOIN sale_audits sa ON SUBSTRING_INDEX(sa.remark,'||',1)=sale_payments.sale_payment_id") + .where("SUBSTRING_INDEX(SUBSTRING_INDEX(sa.remark,'||',-1),' -> ',1) = #{shift_id}") + .first() + end + end diff --git a/app/pdf/close_cashier_customise_pdf.rb b/app/pdf/close_cashier_customise_pdf.rb index f9d673af..2b05394d 100644 --- a/app/pdf/close_cashier_customise_pdf.rb +++ b/app/pdf/close_cashier_customise_pdf.rb @@ -2,7 +2,7 @@ class CloseCashierCustomisePdf < Prawn::Document include ActionView::Helpers::NumberHelper attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width - def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges) + def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -54,7 +54,7 @@ class CloseCashierCustomisePdf < Prawn::Document stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_dinein,total_takeway,total_other_charges) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) end def header (shop_details) @@ -70,7 +70,7 @@ class CloseCashierCustomisePdf < Prawn::Document stroke_horizontal_rule end - def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_dinein,total_takeway,total_other_charges,total_spoile) + def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) move_down 7 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -438,6 +438,16 @@ class CloseCashierCustomisePdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right end + + if total_credit_payments && total_credit_payments.to_f > 0 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Credit Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + end #end for service charges and commercial tax #COMMENTED FOR NO NEED AND NOT CORRECT WHEN OTHER CHARGES # y_position = cursor @@ -520,7 +530,7 @@ class CloseCashierCustomisePdf < Prawn::Document if @overall > 0 y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do - text "Total Overall Discount :", :size => self.item_font_size, :align => :right + text "Total Discount :", :size => self.item_font_size, :align => :right end bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "-#{ number_with_precision(@overall, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right @@ -531,7 +541,25 @@ class CloseCashierCustomisePdf < Prawn::Document end #end total over all discount - + if total_waste.to_f > 0 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Waste :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "(#{ number_with_precision(total_waste, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end + end + + if total_spoile.to_f > 0 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Spoile :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "(#{ number_with_precision(total_spoile, :precision => precision.to_i, :delimiter => delimiter)})", :size => self.item_font_size, :align => :right + end + end y_position = cursor bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do diff --git a/app/pdf/close_cashier_pdf.rb b/app/pdf/close_cashier_pdf.rb index 461022c1..2a42a98d 100755 --- a/app/pdf/close_cashier_pdf.rb +++ b/app/pdf/close_cashier_pdf.rb @@ -2,7 +2,7 @@ class CloseCashierPdf < Prawn::Document include ActionView::Helpers::NumberHelper attr_accessor :label_width,:price_column_width,:page_width, :page_height, :margin, :price_width, :item_width, :header_font_size, :item_font_size,:item_height,:qty_width,:total_width,:item_description_width,:text_width - def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile) + def initialize(printer_settings, shift_sale,shop_details,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,total_dinein,total_takeway,total_other_charges,total_waste,total_spoile,total_credit_payments) self.page_width = printer_settings.page_width #PrintSetting.where("name = ?","Close Cashier").first.page_width self.page_height = printer_settings.page_height self.header_font_size = printer_settings.header_font_size.to_i @@ -54,7 +54,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule - shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_waste,total_spoile,total_other_charges) + shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,printer_settings.precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) end def header (shop_details) @@ -70,7 +70,7 @@ class CloseCashierPdf < Prawn::Document stroke_horizontal_rule end - def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges) + def shift_detail(shift_sale,sale_taxes,other_payment,total_amount_by_account,total_discount_by_account,total_member_discount,precision,delimiter,total_waste,total_spoile,total_other_charges,total_credit_payments) move_down 7 y_position = cursor bounding_box([0,y_position], :width =>self.label_width, :height => self.item_height) do @@ -346,6 +346,16 @@ class CloseCashierPdf < Prawn::Document bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do text "#{number_with_precision(shift_sale.nett_sales, :precision => precision.to_i, :delimiter => delimiter) }", :style => :bold , :size => self.header_font_size - 1, :align => :right end + + if total_credit_payments && total_credit_payments.to_f > 0 + y_position = cursor + bounding_box([0,y_position], :width =>self.item_description_width, :height => 20) do + text "Total Credit Payment :", :size => self.item_font_size, :align => :right + end + bounding_box([self.item_description_width,y_position], :width =>self.price_width, :height => 20) do + text "#{ number_with_precision(total_credit_payments, :precision => precision.to_i, :delimiter => delimiter)}", :size => self.item_font_size, :align => :right + end + end #end for service charges and commercial tax #COMMENTED FOR NO NEED AND NOT CORRECT WHEN OTHER CHARGES # y_position = cursor diff --git a/app/pdf/receipt_bill_a5_pdf.rb b/app/pdf/receipt_bill_a5_pdf.rb index 49ba7530..26add8dc 100644 --- a/app/pdf/receipt_bill_a5_pdf.rb +++ b/app/pdf/receipt_bill_a5_pdf.rb @@ -371,13 +371,15 @@ class ReceiptBillA5Pdf < Prawn::Document def sale_payment(sale_data,precision,delimiter) stroke_horizontal_rule # move_down 10 - sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method") - .where("(CASE WHEN ((SELECT SUM(payment_amount) + sql = "SELECT SUM(payment_amount) FROM sale_payments where payment_method='creditnote' - and sale_id='#{sale_data.sale_id}') - - (SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) + and sale_id='#{sale_data.sale_id}'" + sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) FROM sale_payments where payment_method='creditnote' - and sale_id='#{sale_data.sale_id}') + and sale_id='#{sale_data.sale_id}'" + + sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method") + .where("(CASE WHEN ((#{sql}) - (#{sql1}) ELSE SUM(payment_amount) END FROM sale_payments JOIN sales s ON s.sale_id=sale_payments.sale_id @@ -587,12 +589,14 @@ class ReceiptBillA5Pdf < Prawn::Document end def sign(sale_data) - SalePayment.where("(CASE WHEN ((SELECT SUM(payment_amount) + sql = "SELECT SUM(payment_amount) FROM sale_payments where payment_method='creditnote' - and sale_id='#{sale_data.sale_id}') - - (SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) + and sale_id='#{sale_data.sale_id}'" + sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) FROM sale_payments where payment_method='creditnote' - and sale_id='#{sale_data.sale_id}') + and sale_id='#{sale_data.sale_id}'" + + SalePayment.where("(CASE WHEN ((#{sql}) - (#{sql1}) ELSE SUM(payment_amount) END FROM sale_payments JOIN sales s ON s.sale_id=sale_payments.sale_id diff --git a/app/pdf/receipt_bill_pdf.rb b/app/pdf/receipt_bill_pdf.rb index f352f967..5224eaea 100755 --- a/app/pdf/receipt_bill_pdf.rb +++ b/app/pdf/receipt_bill_pdf.rb @@ -369,13 +369,15 @@ class ReceiptBillPdf < Prawn::Document def sale_payment(sale_data,precision,delimiter) stroke_horizontal_rule #move_down line_move - sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method") - .where("(CASE WHEN ((SELECT SUM(payment_amount) + sql = "SELECT SUM(payment_amount) FROM sale_payments where payment_method='creditnote' - and sale_id='#{sale_data.sale_id}') - - (SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) + and sale_id='#{sale_data.sale_id}'" + sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) FROM sale_payments where payment_method='creditnote' - and sale_id='#{sale_data.sale_id}') + and sale_id='#{sale_data.sale_id}'" + + sale_payments = SalePayment.select("SUM(sale_payments.payment_amount) as payment_amount,sale_payments.payment_method") + .where("(CASE WHEN ((#{sql}) - (#{sql1}) ELSE SUM(payment_amount) END FROM sale_payments JOIN sales s ON s.sale_id=sale_payments.sale_id @@ -588,12 +590,14 @@ class ReceiptBillPdf < Prawn::Document end def sign(sale_data) - SalePayment.where("(CASE WHEN ((SELECT SUM(payment_amount) + sql = "SELECT SUM(payment_amount) FROM sale_payments where payment_method='creditnote' - and sale_id='#{sale_data.sale_id}') - - (SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) + and sale_id='#{sale_data.sale_id}'" + sql1 = "SELECT CASE WHEN s.amount_changed > 0 and (s.amount_received - s.amount_changed) = s.grand_total THEN ( SELECT SUM(payment_amount) FROM sale_payments where payment_method='creditnote' - and sale_id='#{sale_data.sale_id}') + and sale_id='#{sale_data.sale_id}'" + + SalePayment.where("(CASE WHEN ((#{sql}) - (#{sql1}) ELSE SUM(payment_amount) END FROM sale_payments JOIN sales s ON s.sale_id=sale_payments.sale_id diff --git a/db/migrate/20170403174111_create_sale_audits.rb b/db/migrate/20170403174111_create_sale_audits.rb index 1cf609df..427cd74f 100755 --- a/db/migrate/20170403174111_create_sale_audits.rb +++ b/db/migrate/20170403174111_create_sale_audits.rb @@ -3,14 +3,15 @@ class CreateSaleAudits < ActiveRecord::Migration[5.1] create_table :sale_audits, :id => false do |t| t.string :sale_audit_id, :limit => 16, :primary_key => true #custom primary key - to ensure consistence for cloud syncing - t.string :sale_id, foreign_key: true, :limit => 16 - t.string :action, :null => false - t.datetime :action_at, :null => false + t.string :sale_id, foreign_key: true, :index => true, :limit => 16 + t.string :action, :null => false, :index => true + t.datetime :action_at, :null => false, :index => true t.string :action_by, :null => false t.string :approved_by, :null => true t.datetime :approved_at, :null => true - t.text :remark + t.text :remark, :index => true t.timestamps end + add_index :sale_audits, [:sale_id, :action, :action_at, :remark] end end diff --git a/db/migrate/20170622050926_create_customers.rb b/db/migrate/20170622050926_create_customers.rb index a98002db..f54318b4 100755 --- a/db/migrate/20170622050926_create_customers.rb +++ b/db/migrate/20170622050926_create_customers.rb @@ -2,7 +2,7 @@ class CreateCustomers < ActiveRecord::Migration[5.1] def change create_table :customers, :id => false do |t| t.string :customer_id, :limit => 16, :primary_key => true #custom foreign_key to prevent conflict during sync - t.string :name, :null => false + t.string :name, :null => false, :index => true t.string :company t.string :email t.string :contact_no, :unique => true @@ -20,6 +20,6 @@ class CreateCustomers < ActiveRecord::Migration[5.1] t.json :tax_profiles t.string :image_path end - add_index :customers, [:membership_id, :customer_type] + add_index :customers, [:name, :membership_id, :customer_type] end end