From 386187551aa328858bfca8733fe74e265d5f4753 Mon Sep 17 00:00:00 2001 From: Mauricio Voto Date: Wed, 11 Oct 2017 11:31:07 -0300 Subject: [PATCH 1/3] add handbook initial structure --- README.md | 25 +++++++++++++++ app/controllers/customers_controller.rb | 31 +++++++++++-------- app/models/customer.rb | 1 + app/models/device.rb | 19 ++++++------ app/models/handbook.rb | 4 +++ db/migrate/20170809023316_create_handbooks.rb | 10 ++++++ db/schema.rb | 11 ++++++- spec/factories/handbooks.rb | 7 +++++ spec/models/handbook_spec.rb | 5 +++ 9 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 app/models/handbook.rb create mode 100644 db/migrate/20170809023316_create_handbooks.rb create mode 100644 spec/factories/handbooks.rb create mode 100644 spec/models/handbook_spec.rb diff --git a/README.md b/README.md index 8c0ed43..bd90dfc 100644 --- a/README.md +++ b/README.md @@ -23,3 +23,28 @@ VERSION 1: VERSION 2: - Add an export button on customers to generate a .xls file - Add customer's details print version with button / link +- Separate login / user roles(to be discussed) + +#### Reuniao 15/02 + +1- Melhorar o layout [FEITO] +2- Melhorar os detalhes do cliente: apresentar todas as infos possiveis [FEITO] +3- Adicionar a busca por data de compra de aparelho(ou melhor, criar uma tela com + o filtro aplicado, com ordenação inicial feita pela data de compra mais antiga) [FEITO] +4- Possibilidade de anexar a audiometria(tanto imagens como pdf) - upload [FEITO] +5- **Criar uma ficha cadastral de cada cliente para impressão** +6- Adicionar uma sessão de prontuário(com data e informação) para + efeito de histórico - adicionar uma listagem na tela de detalhes do cliente, similar à listagem de aparelhos[WIP] +7- Melhoria no cadastro / busca de clientes(atualmente temos problemas com dados duplicados e dados que se perdem)[FEITO] + +* Há uma necessidade de ter uma ficha cadastral de cada cliente +* Existe a necessidade de adicionar um prontuário(com data e informação) para + efeito de histórico - na tela de detalhes do cliente, customer has many handbooks + agora é tocar o esquema de controller + view assim como Devices +* Adicionar em Gráficos, infos de Dashboard: total de clientes, total de aparelhos, etc +e os gráficos(pizza) de usuários por tipos talvez + +# AWS KEYS + +AKIAIFXOVGXYDBXKXCOA +UP17kD681dCQUPehnm1HAv/1TjOmWu5AR8NjrRC1 diff --git a/app/controllers/customers_controller.rb b/app/controllers/customers_controller.rb index 7298792..dd2fc5e 100644 --- a/app/controllers/customers_controller.rb +++ b/app/controllers/customers_controller.rb @@ -4,7 +4,9 @@ class CustomersController < ApplicationController def index @q = Customer.search(params[:q]) - @customers = @q.result.includes(:address, :devices).order(:name).paginate(page: params[:page], per_page: 10) + @customers = @q.result.includes(:address, :devices).order(:name).paginate( + page: params[:page], per_page: 10 + ) end def show; end @@ -19,7 +21,8 @@ def edit; end def create @customer = Customer.new(customer_params) if @customer.save - redirect_to customer_path(@customer), notice: I18n.t('controller.messages.create') + redirect_to customer_path(@customer), notice: + I18n.t('controller.messages.create') else render :new end @@ -27,7 +30,8 @@ def create def update if @customer.update(customer_params) - redirect_to customer_path(@customer), notice: I18n.t('controller.messages.update') + redirect_to customer_path(@customer), notice: + I18n.t('controller.messages.update') else render :edit end @@ -39,15 +43,16 @@ def destroy end private - def set_customer - @customer = Customer.find(params[:id]) if params[:id].present? - @states = State.order(:acronym) - end - def customer_params - params.require(:customer).permit(:name, :email, :phone, :type, :cpf, :rg, - :dob, :cellphone, :cnpj, :state_registration, :gender, :career, :re, :audiometry, - :phone_ddd, :cellphone_ddd, :observation, address_attributes: [:street, :number, - :zipcode, :city_id, :state_id, :neighborhood, :complement]) - end + def set_customer + @customer = Customer.find(params[:id]) if params[:id].present? + @states = State.order(:acronym) + end + + def customer_params + params.require(:customer).permit(:name, :email, :phone, :type, :cpf, :rg, + :dob, :cellphone, :cnpj, :state_registration, :gender, :career, :re, :audiometry, + :phone_ddd, :cellphone_ddd, :observation, address_attributes: [:street, :number, + :zipcode, :city_id, :state_id, :neighborhood, :complement]) + end end diff --git a/app/models/customer.rb b/app/models/customer.rb index ea304a3..a55ddd5 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -3,6 +3,7 @@ class Customer < ActiveRecord::Base has_one :address, dependent: :destroy has_many :devices, dependent: :destroy + has_many :handbooks, dependent: :destroy accepts_nested_attributes_for :address accepts_nested_attributes_for :devices, allow_destroy: true diff --git a/app/models/device.rb b/app/models/device.rb index ed52882..03976d7 100644 --- a/app/models/device.rb +++ b/app/models/device.rb @@ -1,18 +1,17 @@ class Device < ActiveRecord::Base - - TYPES = [ 'CIC', 'ITC', 'ITE', 'BTE', 'ADP.A', 'REC.C.' ] - BATTERIES = [ '10', '13', '312', '675' ] - EAR = [ 'Direito', 'Esquerdo' ] - STORES = [ 'Unidade I - Santo André', 'Unidade II - Barra Funda', - 'Unidade III - Santos', 'Unidade IV - Praia Grande', - 'Interior de São Paulo'] + TYPES = ['CIC', 'ITC', 'ITE', 'BTE', 'ADP.A', 'REC.C.'].freeze + BATTERIES = %w[10 13 312 675].freeze + EAR = %w[Direito Esquerdo].freeze + STORES = ['Unidade I - Santo André', 'Unidade II - Barra Funda', + 'Unidade III - Santos', 'Unidade IV - Praia Grande', + 'Interior de São Paulo'].freeze belongs_to :customer validates_presence_of :brand, :model, :serial_number, :warantee, :_type, - :ear, :battery - validates :store, presence: true, if: Proc.new { |a| a.other_store.blank? } - validates :other_store, presence: true, if: Proc.new { |a| a.store.blank? } + :ear, :battery + validates :store, presence: true, if: proc { |a| a.other_store.blank? } + validates :other_store, presence: true, if: proc { |a| a.store.blank? } validates :ear, inclusion: { in: EAR } validates :_type, inclusion: { in: TYPES } validates :store, inclusion: { in: STORES }, allow_blank: true diff --git a/app/models/handbook.rb b/app/models/handbook.rb new file mode 100644 index 0000000..c850b83 --- /dev/null +++ b/app/models/handbook.rb @@ -0,0 +1,4 @@ +class Handbook < ActiveRecord::Base + belongs_to :customer + validates_presence_of :information, :customer_id +end diff --git a/db/migrate/20170809023316_create_handbooks.rb b/db/migrate/20170809023316_create_handbooks.rb new file mode 100644 index 0000000..b02efd6 --- /dev/null +++ b/db/migrate/20170809023316_create_handbooks.rb @@ -0,0 +1,10 @@ +class CreateHandbooks < ActiveRecord::Migration + def change + create_table :handbooks do |t| + t.string :information + t.references :customer, index: true + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 7906906..d738230 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170521222104) do +ActiveRecord::Schema.define(version: 20170809023316) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -80,6 +80,15 @@ t.string "serial_number" end + create_table "handbooks", force: true do |t| + t.string "information" + t.integer "customer_id" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "handbooks", ["customer_id"], name: "index_handbooks_on_customer_id", using: :btree + create_table "states", force: true do |t| t.string "acronym" t.string "name" diff --git a/spec/factories/handbooks.rb b/spec/factories/handbooks.rb new file mode 100644 index 0000000..91ef563 --- /dev/null +++ b/spec/factories/handbooks.rb @@ -0,0 +1,7 @@ +FactoryGirl.define do + factory :handbook do + information "MyString" +customer nil + end + +end diff --git a/spec/models/handbook_spec.rb b/spec/models/handbook_spec.rb new file mode 100644 index 0000000..fb3bcf3 --- /dev/null +++ b/spec/models/handbook_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Handbook, :type => :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 337a947cb0769b9d51ad8795e717ad3d7ca0a039 Mon Sep 17 00:00:00 2001 From: Mauricio Voto Date: Tue, 17 Oct 2017 12:36:07 -0200 Subject: [PATCH 2/3] add audiometry translation key --- config/locales/pt-BR.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index 599dee4..678abf5 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -55,6 +55,7 @@ pt-BR: gender: "Sexo" state_registration: "Inscrição Estadual" observation: "Observações" + audiometry: "Audiometria" device: _type: "Tipo de Aparelho" purchased_at: "Data de Compra" From 9ea5f1564663c46c379693b253906a4ed059147d Mon Sep 17 00:00:00 2001 From: Mauricio Voto Date: Tue, 17 Oct 2017 12:43:45 -0200 Subject: [PATCH 3/3] remove sensitive data from README --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index bd90dfc..2793f3f 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,3 @@ VERSION 2: * Adicionar em Gráficos, infos de Dashboard: total de clientes, total de aparelhos, etc e os gráficos(pizza) de usuários por tipos talvez -# AWS KEYS - -AKIAIFXOVGXYDBXKXCOA -UP17kD681dCQUPehnm1HAv/1TjOmWu5AR8NjrRC1