Skip to content

Commit 74c99f6

Browse files
committed
Add invoice upload
1 parent 26b27c8 commit 74c99f6

File tree

9 files changed

+76
-8
lines changed

9 files changed

+76
-8
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class InvoicesController < ApplicationController
2+
before_action :require_group_write
3+
4+
def create
5+
item = Item.find(params[:item_id])
6+
item.invoice.attach(params[:photo])
7+
redirect_to edit_item_path(item)
8+
end
9+
10+
def destroy
11+
item = Item.find(params[:item_id])
12+
item.invoice.purge
13+
redirect_to edit_item_path(item)
14+
end
15+
end

app/controllers/items_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,6 @@ def item_params
9595
.permit(:name, :description, :purchase_date, :entry_date, :group_id,
9696
:organization, :number, :parent_id, :specific_name, :serial,
9797
:location, :at_who, :warranty, :comment, :inventory_number,
98-
:entry_price, :accountancy_state, :photo)
98+
:entry_price, :accountancy_state, :photo, :invoice)
9999
end
100100
end

app/models/item.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class Item < ApplicationRecord
1919
has_paper_trail
2020
belongs_to :group
2121
has_many_attached :photos
22+
has_one_attached :invoice
2223
belongs_to :parent, class_name: 'Item', foreign_key: :parent_id, optional: true
2324
has_many :children, class_name: 'Item', foreign_key: :parent_id, inverse_of: :parent
2425

app/views/items/_form.html.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,13 @@
168168
<%= f.file_field :photo, accept: :'image/*' %>
169169
</div>
170170
</div>
171+
172+
<div class="uk-margin">
173+
<%= f.label :invoice, class: 'uk-form-label' %>
174+
<div class="uk-form-controls">
175+
<%= f.file_field :invoice, accept: :'image/*' %>
176+
</div>
177+
</div>
171178
<%end%>
172179

173180
<div class="uk-width-1-1">
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<% if @item.invoice.attached? %>
2+
<div class="uk-inline">
3+
<%= image_tag @item.invoice.variant(resize: '1000x1000') %>
4+
<div class="uk-overlay uk-position-top">
5+
<div class="uk-position-right">
6+
<%= form_tag item_invoice_path(@item, @item.invoice.id), method: :delete do %>
7+
<a href="javascript:{}" onclick="this.parentElement.submit();" uk-icon="trash"
8+
class="uk-icon-link photo-delete uk-overlay-default uk-padding-small"></a>
9+
<% end %>
10+
</div>
11+
</div>
12+
</div>
13+
<% else %>
14+
<div class="uk-text-center uk-margin">
15+
Nincs még számla
16+
</div>
17+
<% end %>
18+
19+
<%= form_tag item_invoices_path(@item), method: :post, multipart: true, class: 'uk-form-horizontal' do |f| %>
20+
<div class="uk-margin">
21+
<%= label_tag :photo, 'Számla feltöltése', class: 'uk-form-label' %>
22+
<div class="uk-form-controls">
23+
<%= file_field_tag :photo, accept: :'image/*' %>
24+
</div>
25+
</div>
26+
<div class="uk-width-1-1">
27+
<%= submit_tag t(:upload), class: 'uk-button uk-button-primary uk-align-center' %>
28+
</div>
29+
<% end %>

app/views/items/edit.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<%= render 'form', item: @item, image_uploader: false %>
1515
</div>
1616
<div class="uk-width-1-3">
17+
<h3>Számla</h3>
18+
<%= render 'invoice_form' %>
19+
<h3>Képek</h3>
1720
<%= render 'picture_form' %>
1821
</div>
1922
</div>

app/views/items/show.html.erb

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</div>
1010
</div>
1111

12-
<div class="uk-grid-collapse" uk-grid>
12+
<div class="uk-grid-small" uk-grid>
1313
<div class="uk-child-width-1-1 uk-width-2-3@s uk-width-1-1">
1414
<ul uk-accordion>
1515
<li class="uk-open">
@@ -100,15 +100,25 @@
100100
<%= @item.check_form %>
101101
</div>
102102

103-
<div class="uk-grid-small uk-child-width-1-2 uk-width-1-3@s uk-width-1-1 uk-margin-small-top" uk-grid>
103+
<div class="uk-width-1-3@s uk-width-1-1 uk-margin-small-top">
104104

105-
<% if @item.photos.attached? %>
106-
<% @item.photos.each do |photo| %>
107-
<%= link_to url_for(photo) do %>
108-
<%= image_tag photo.variant(resize: '1000x1000') %>
105+
<% if @item.invoice.attached? %>
106+
<h3 class="uk-margin-remove">Számla</h3>
107+
<%= link_to url_for(@item.invoice) do %>
108+
<%= image_tag @item.invoice.variant(resize: '1000x1000'), class: 'uk-width-1-1' %>
109109
<% end %>
110110
<% end %>
111-
<% end %>
111+
112+
<% if @item.photos.attached? %>
113+
<h3>Képek</h3>
114+
<div class="uk-grid-small uk-child-width-1-2" uk-grid>
115+
<% @item.photos.each do |photo| %>
116+
<%= link_to url_for(photo) do %>
117+
<%= image_tag photo.variant(resize: '1000x1000') %>
118+
<% end %>
119+
<% end %>
120+
</div>
121+
<% end %>
112122

113123
</div>
114124
</div>

config/locales/hu.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ hu:
7171
status: Státusz
7272
warranty: Garancia
7373
update: Frissítés
74+
photo: Kép
75+
invoice: Számla
7476
group:
7577
name: Név
7678
user:

config/routes.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# Items routes
2121
resources :items do
2222
resources :photos, only: %i[create destroy]
23+
resources :invoices, only: %i[create destroy]
2324

2425
post 'check', to: 'items#update_last_check', as: :check
2526
get 'versions/:version_idx', to: 'items#show', as: :version

0 commit comments

Comments
 (0)