Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,24 @@ 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

31 changes: 18 additions & 13 deletions app/controllers/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,15 +21,17 @@ 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
end

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
Expand All @@ -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
1 change: 1 addition & 0 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 9 additions & 10 deletions app/models/device.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/models/handbook.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Handbook < ActiveRecord::Base
belongs_to :customer
validates_presence_of :information, :customer_id
end
1 change: 1 addition & 0 deletions config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20170809023316_create_handbooks.rb
Original file line number Diff line number Diff line change
@@ -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
11 changes: 10 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions spec/factories/handbooks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FactoryGirl.define do
factory :handbook do
information "MyString"
customer nil
end

end
5 changes: 5 additions & 0 deletions spec/models/handbook_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe Handbook, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
end