Skip to content

Commit

Permalink
Update receipt item view
Browse files Browse the repository at this point in the history
  • Loading branch information
sachac committed May 29, 2015
1 parent a79e095 commit 1aa1c67
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/receipt_items_controller.rb
Expand Up @@ -5,7 +5,7 @@ class ReceiptItemsController < ApplicationController
# GET /receipt_items
# GET /receipt_items.json
def index
@receipt_items = current_account.receipt_items.order('date DESC').joins('LEFT JOIN receipt_item_types ON receipt_items.receipt_item_type_id=receipt_item_types.id').select('receipt_items.*, receipt_item_types.friendly_name')
@receipt_items = current_account.receipt_items.order('date DESC').joins('LEFT JOIN receipt_item_types ON receipt_items.receipt_item_type_id=receipt_item_types.id LEFT JOIN receipt_item_categories ON receipt_item_types.receipt_item_category_id=receipt_item_categories.id').select('receipt_items.*, receipt_item_types.friendly_name, receipt_item_types.receipt_item_category_id, receipt_item_categories.name AS category_name')
params[:start] = (current_account.receipt_items.minimum(:date) - 1.day).to_s if params[:start].blank? and current_account.receipt_items.size > 0
params[:end] ||= (Time.zone.now + 1.day).midnight.to_s
prepare_filters [:filter_string, :date_range]
Expand Down
2 changes: 2 additions & 0 deletions app/models/receipt_item.rb
Expand Up @@ -2,6 +2,7 @@ class ReceiptItem < ActiveRecord::Base
belongs_to :user
belongs_to :receipt_item_type
delegate :friendly_name, to: :receipt_item_type, allow_nil: true
delegate :category_name, to: :receipt_item_type, allow_nil: true
before_save :update_total

def update_total
Expand Down Expand Up @@ -67,6 +68,7 @@ def self.create_batch(user, csv)
date
name
friendly_name
category_name
quantity
unit
unit_price
Expand Down
2 changes: 1 addition & 1 deletion app/models/receipt_item_type.rb
Expand Up @@ -2,7 +2,7 @@ class ReceiptItemType < ActiveRecord::Base
has_many :receipt_items
belongs_to :user
belongs_to :receipt_item_category

delegate :name, to: :receipt_item_category, prefix: :category, allow_nil: true
def self.map(user, receipt_name, friendly_name, category_id = nil)
type = user.receipt_item_types.create(friendly_name: friendly_name,
receipt_name: receipt_name,
Expand Down
6 changes: 4 additions & 2 deletions app/views/receipt_items/index.html.haml
Expand Up @@ -8,21 +8,23 @@
%table.table.table-bordered.full
%tr
%th Store
%th Date
%th(width=100) Date
%th Name
%th Friendly name
%th Category
%th Quantity
%th Unit
%th Unit price
%th Total
%th Notes
%th
%th(width=50)
- @receipt_items.each do |receipt_item|
%tr
%td= receipt_item.store
%td= receipt_item.date
%td= link_to receipt_item.name, receipt_items_path(params.merge(filter_string: receipt_item.name))
%td= link_to receipt_item.friendly_name, receipt_item.receipt_item_type if receipt_item.receipt_item_type
%td= link_to receipt_item.category_name, receipt_item_category_path(receipt_item.receipt_item_category_id) if receipt_item.receipt_item_category_id
%td= '%0.3f' % receipt_item.quantity if receipt_item.quantity
%td= receipt_item.unit
%td= '%0.3f' % receipt_item.unit_price if receipt_item.unit_price
Expand Down

0 comments on commit 1aa1c67

Please sign in to comment.