Browse Source

lk | adds ability to print multiple receipts for freecyclery clients

master
Louis Knapp 9 years ago
parent
commit
2ca3ae21a8
  1. 3
      app/assets/stylesheets/client_receipt.scss
  2. 13
      app/controllers/clients_controller.rb
  3. 1
      app/models/bike.rb
  4. 6
      app/models/client.rb
  5. 74
      app/views/clients/_receipt.html.haml
  6. 4
      app/views/clients/print_receipts.html.haml
  7. 18
      app/views/clients/print_select.html.haml
  8. 2
      app/views/static_pages/home.html.haml
  9. 3
      config/routes.rb
  10. 58
      db/schema.rb

3
app/assets/stylesheets/client_receipt.scss

@ -1,4 +1,4 @@
.freecyclery-receipt{
.print-receipts, .freecyclery-receipt{
h2 {
font-size: 18px;
}
@ -7,6 +7,7 @@
border-bottom: 5px solid black;
}
.receipt{
page-break-inside: avoid;
margin: 10px;
border: 5px solid black;
height: 400px;

13
app/controllers/clients_controller.rb

@ -31,6 +31,15 @@ class ClientsController < ApplicationController
end
end
def print_select
@clients = Client.includes(:bike).where.not(bike_id: nil).order(application_date: :desc).paginate(:page => params[:page], :per_page => 30)
end
def print_receipts
client_ids = print_params.map{|key, value| key if value == "1"}.compact
@clients = Client.find(client_ids)
end
private
def set_client
@client = Client.find(params[:id])
@ -60,4 +69,8 @@ class ClientsController < ApplicationController
:pickup_date,
:volunteer_at_pickup)
end
def print_params
params.require(:print_clients)
end
end

1
app/models/bike.rb

@ -5,6 +5,7 @@ class Bike < ActiveRecord::Base
validates :bike_type, presence: true
validates :color, presence: true
validates :serial_number, presence: true
has_one :client
def self.bike_types
[

6
app/models/client.rb

@ -1,7 +1,7 @@
class Client < ActiveRecord::Base
# TODO: figure out why application_date validation is fubar
# validates :application_date, presence: true
has_one :bike
belongs_to :bike
belongs_to :agency
def self.waiting_list
@ -20,8 +20,4 @@ class Client < ActiveRecord::Base
Client.all.select{|client| client.application_voided || client.pickup_date}
end
def bike
Bike.find(self.bike_id)
end
end

74
app/views/clients/_receipt.html.haml

@ -0,0 +1,74 @@
.col-xs-6
.receipt
%h2
%strong= client.bike.name
%br
.horizontal-line
.client-information
= client.name
%br
= client.agency.agency_name if client.agency
.horizontal-line
%br
Includes:
%br
= 'Helmet' if client.helmet
%br
= 'Lock' if client.lock
%br
%br
Date Received
%br
_______________
%br
Client Signature
%br
________________
%br
Recyclery Volunteer Initials
%br
___
%br
CLIENT COPY
.col-xs-6
.receipt
%h2
%strong= client.bike.name
%br
.horizontal-line
.client-information
= client.name
%br
= client.agency.agency_name if client.agency
.horizontal-line
.row
.col-xs-6
%br
= 'Will make 25$ payment for lock and helmet' if client.will_pay
%br
Includes:
%br
= 'Helmet' if client.helmet
%br
= 'Lock' if client.lock
%br
%br
Date Received
%br
_______________
%br
Client Signature
%br
________________
.col-xs-6
.client-info-header CLIENT INFO
.client-email= "Agency Email: " + client.agency.email
.client-phone= "Agency Phone #: " + client.agency.phone_number
.client-photo-consent [ ] I grant consent to the Recyclery to use and publish photographs of me.
%br
Recyclery Volunteer Initials
%br
___
%br
RECYCLERY COPY

4
app/views/clients/print_receipts.html.haml

@ -0,0 +1,4 @@
.container.print-receipts
- @clients.each do |client|
.row
= render partial: "receipt", locals: {client: client}

18
app/views/clients/print_select.html.haml

@ -0,0 +1,18 @@
.container
%h1 Select the clients whose receipts you would like to print
=form_tag("/clients/print_receipts", method: "get") do
%table.table.table-striped.table-bordered.table-hover
%thead
%tr
%th Client
%th Bike
%th Select
-@clients.each do |client|
%tr
%td= client.name
%td= client.bike.name
%td= check_box("print_clients", client.id)
=will_paginate @clients
%br
=submit_tag 'Generate Receipts', class: "btn btn-default"

2
app/views/static_pages/home.html.haml

@ -15,6 +15,8 @@
%br
= link_to "Freecyclery Agencies", agencies_path
%br
= link_to "Print Client Receipts", print_select_clients_path
%br
= link_to "Freecyclery Closed Applications", closed_applications_path
%br
= link_to "Available Bikes", available_bikes_path

3
config/routes.rb

@ -18,6 +18,9 @@ Bikedb::Application.routes.draw do
resources :agencies
resources :clients do
get 'receipt' => 'freecyclery#receipt'
get 'print_select' => 'clients#print_select', on: :collection
get 'print_receipts' => 'clients#print_receipts', on: :collection
end
get 'closed_applications' => 'freecyclery#closed_applications'

58
db/schema.rb

@ -17,26 +17,26 @@ ActiveRecord::Schema.define(version: 20151230021120) do
enable_extension "plpgsql"
create_table "agencies", force: :cascade do |t|
t.string "agency_name"
t.string "contact_name"
t.string "street_address"
t.string "city"
t.string "state"
t.string "postal_code"
t.string "phone_number"
t.string "email"
t.string "agency_name", limit: 255
t.string "contact_name", limit: 255
t.string "street_address", limit: 255
t.string "city", limit: 255
t.string "state", limit: 255
t.string "postal_code", limit: 255
t.string "phone_number", limit: 255
t.string "email", limit: 255
end
create_table "bikes", force: :cascade do |t|
t.string "entry_date"
t.string "brand"
t.string "model"
t.string "bike_type"
t.string "color"
t.string "serial_number"
t.string "entry_date", limit: 255
t.string "brand", limit: 255
t.string "model", limit: 255
t.string "bike_type", limit: 255
t.string "color", limit: 255
t.string "serial_number", limit: 255
t.text "work_done"
t.text "new_parts"
t.string "price"
t.string "price", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
t.float "seat_tube_size"
@ -49,17 +49,17 @@ ActiveRecord::Schema.define(version: 20151230021120) do
end
create_table "clients", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.string "first_name", limit: 255
t.string "last_name", limit: 255
t.date "application_date_bkp"
t.string "gender"
t.string "gender", limit: 255
t.integer "age"
t.boolean "helmet"
t.boolean "lock"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "bike_id"
t.string "bike_type_requested"
t.string "bike_type_requested", limit: 255
t.boolean "will_pay"
t.integer "agency_id"
t.text "notes"
@ -67,7 +67,7 @@ ActiveRecord::Schema.define(version: 20151230021120) do
t.integer "number_of_calls"
t.boolean "application_voided"
t.date "pickup_date_bkp"
t.string "volunteer_at_pickup"
t.string "volunteer_at_pickup", limit: 255
t.float "weight"
t.float "height"
t.datetime "application_date"
@ -78,16 +78,16 @@ ActiveRecord::Schema.define(version: 20151230021120) do
add_index "clients", ["bike_id"], name: "index_clients_on_bike_id", using: :btree
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.string "email", limit: 255, default: "", null: false
t.string "encrypted_password", limit: 255, default: "", null: false
t.string "reset_password_token", limit: 255
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.string "current_sign_in_ip", limit: 255
t.string "last_sign_in_ip", limit: 255
t.datetime "created_at"
t.datetime "updated_at"
end
@ -96,9 +96,9 @@ ActiveRecord::Schema.define(version: 20151230021120) do
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
create_table "volunteers", force: :cascade do |t|
t.string "name"
t.string "email"
t.string "phone"
t.string "name", limit: 255
t.string "email", limit: 255
t.string "phone", limit: 255
t.date "orientation_date"
t.integer "other_volunteer_hours"
t.text "referral"

Loading…
Cancel
Save