From 2ca3ae21a8453b20dbd8d05f7f976b5866972372 Mon Sep 17 00:00:00 2001 From: Louis Knapp Date: Sat, 7 May 2016 10:14:30 -0500 Subject: [PATCH] lk | adds ability to print multiple receipts for freecyclery clients --- app/assets/stylesheets/client_receipt.scss | 3 +- app/controllers/clients_controller.rb | 13 ++++ app/models/bike.rb | 1 + app/models/client.rb | 6 +- app/views/clients/_receipt.html.haml | 74 ++++++++++++++++++++++ app/views/clients/print_receipts.html.haml | 4 ++ app/views/clients/print_select.html.haml | 18 ++++++ app/views/static_pages/home.html.haml | 2 + config/routes.rb | 3 + db/schema.rb | 58 ++++++++--------- 10 files changed, 147 insertions(+), 35 deletions(-) create mode 100644 app/views/clients/_receipt.html.haml create mode 100644 app/views/clients/print_receipts.html.haml create mode 100644 app/views/clients/print_select.html.haml diff --git a/app/assets/stylesheets/client_receipt.scss b/app/assets/stylesheets/client_receipt.scss index c9440b8..44fcc71 100644 --- a/app/assets/stylesheets/client_receipt.scss +++ b/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; diff --git a/app/controllers/clients_controller.rb b/app/controllers/clients_controller.rb index d9bb3fa..1e816c5 100644 --- a/app/controllers/clients_controller.rb +++ b/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 diff --git a/app/models/bike.rb b/app/models/bike.rb index 963d0e7..4489760 100644 --- a/app/models/bike.rb +++ b/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 [ diff --git a/app/models/client.rb b/app/models/client.rb index 12e0f62..be867bd 100644 --- a/app/models/client.rb +++ b/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 diff --git a/app/views/clients/_receipt.html.haml b/app/views/clients/_receipt.html.haml new file mode 100644 index 0000000..cc59f0c --- /dev/null +++ b/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 diff --git a/app/views/clients/print_receipts.html.haml b/app/views/clients/print_receipts.html.haml new file mode 100644 index 0000000..93ab7cb --- /dev/null +++ b/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} diff --git a/app/views/clients/print_select.html.haml b/app/views/clients/print_select.html.haml new file mode 100644 index 0000000..0aa6409 --- /dev/null +++ b/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" diff --git a/app/views/static_pages/home.html.haml b/app/views/static_pages/home.html.haml index 1ecf33f..05c6e12 100644 --- a/app/views/static_pages/home.html.haml +++ b/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 diff --git a/config/routes.rb b/config/routes.rb index 2ccb08e..8ad0728 100644 --- a/config/routes.rb +++ b/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' diff --git a/db/schema.rb b/db/schema.rb index 69bc805..0e34d3f 100644 --- a/db/schema.rb +++ b/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"