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
5 changes: 3 additions & 2 deletions app/assets/images/icons.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions app/assets/stylesheets/components/_button_primary.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
margin-bottom: var(--padding-md);
display: flex;
align-items: center;
text-decoration: none;
}

.button-primary svg {
Expand Down
15 changes: 15 additions & 0 deletions app/assets/stylesheets/sales/_sale.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.sale {
display: grid;
grid-template-columns: 1fr 1fr;
column-gap: calc(var(--padding-md)*2);
}

.sale span:first-child {
font-weight: var(--font-bold);
overflow: hidden;
text-overflow: ellipsis;
}

.sale .button-primary {
justify-self: start;
}
26 changes: 26 additions & 0 deletions app/assets/stylesheets/users/show.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,29 @@
border-top: solid var(--primary-200) 2px;
padding-top: var(--padding-md);
}


.card-sales{
grid-row: 5/6;
background-color: white;
}

.card-details-sales{
border-left: 0.4rem solid var(--primary-600);
background-color: white;
}

.card-content-sales{
flex: 2;
font-size: var(--text-md);
color: var(--gray-800);
font-weight: var(--font-medium);
grid-column: 2 / 3;
display: grid;
row-gap: var(--padding-md);
}

.card-content-sales > * + * {
border-top: solid var(--primary-200) 2px;
padding-top: var(--padding-md);
}
4 changes: 4 additions & 0 deletions app/controllers/sales_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ def owner
def sales_params
params.require(:sale).permit(:duration, :payment_method_id, articles_sales_attributes: [:article_id, :quantity])
end

def show_invoice
send_file(sale.invoice.pdf, type: 'application/pdf', disposition: 'inline')
end
end
1 change: 1 addition & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def show
@machines = @user.machines.includes(:ip).order(created_at: :asc)
@subscriptions = @user.subscriptions.order(created_at: :desc)
@free_accesses = @user.free_accesses.order(created_at: :desc)
@sales = @user.sales_as_client.order(created_at: :desc)
end

def new
Expand Down
22 changes: 22 additions & 0 deletions app/views/sales/_sale.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<%# locals: (sale:) -%>

<div class="sale">

<%sale.articles_sales.each do |article_sale| %>
<b><%= article_sale.article.name %> <%if article_sale.quantity > 1 %> (x<%= article_sale.quantity %>) <% end %></b>
<p>Price : <%= number_to_currency(article_sale.article.price * article_sale.quantity / 100, locale: :fr) %> </p>
<% end %>

<%if sale.subscription%>
<b>Internet subscription</b>
<p><%= time_with_relative_tag sale.subscription.start_at %> - <%= time_with_relative_tag sale.subscription.end_at %> (<%= pluralize(sale.subscription.duration, "month") %>)</p>
<% end %>

<p>Payment method: <%= sale.payment_method.name %></p>
<%= link_to(sale.invoice.pdf, class: 'button-primary', download: true) do %>
Invoice
<%= svg_icon_tag 'icon_pdf' %>
<% end %>


</div>
31 changes: 28 additions & 3 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
</h1>

<div class="container">
<% if can?(:create, Sale) %>
<%= render "components/buttons/button_primary_create", text: "Sell", path: new_user_sale_path(@user), aria_label: "Create a sell" %>
<% end %>


<div class="card-details-container card-user card-details-user ">
<div class="card card-details">
<div class="card-title">
Expand Down Expand Up @@ -76,6 +75,7 @@

<div class="divider"></div>
</div>

<div class="card card-subscriptions card-content">

<div class="card-content-subscriptions">
Expand Down Expand Up @@ -106,5 +106,30 @@
</div>

</div>

<div class="card-details-container card-details-sales">
<div class="card card-details">

<div class="card-title">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><!--! Font Awesome Pro 6.2.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license (Commercial License) Copyright 2022 Fonticons, Inc. -->
<path xmlns="http://www.w3.org/2000/svg" d="M224 256c70.7 0 128-57.3 128-128S294.7 0 224 0S96 57.3 96 128s57.3 128 128 128zm-45.7 48C79.8 304 0 383.8 0 482.3C0 498.7 13.3 512 29.7 512H418.3c16.4 0 29.7-13.3 29.7-29.7C448 383.8 368.2 304 269.7 304H178.3z"/>
</svg>
<h2>Sales and invoices</h2>
</div>
<% if can?(:create, Sale) %>
<%= render "components/buttons/button_primary_create", text: "Sell", path: new_user_sale_path(@user), aria_label: "Create a sell" %>
<% end %>
</div>

<div class="divider"></div>
</div>
<div class="card card-sales card-content">

<div class="card-content-sales">
<%= render(@sales) || "No sales" %>
</div>

</div>

</div>
</main>
4 changes: 4 additions & 0 deletions config/storage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ local:
service: Disk
root: <%= Rails.root.join("storage") %>

test_fixtures:
service: Disk
root: <%= Rails.root.join("tmp/storage_fixtures") %>

# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)
# amazon:
# service: S3
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/active_storage/attachments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
invoice1_pdf:
name: pdf
record: sale_ironman_cable_6_months (Invoice)
blob: invoice1_pdf_blob

invoice2_pdf:
name: pdf
record: sale_pepper_1_year (Invoice)
blob: invoice2_pdf_blob

invoice3_pdf:
name: pdf
record: refund_ironman_cable_4_months (Invoice)
blob: invoice3_pdf_blob

invoice4_pdf:
name: pdf
record: sale_ironman_deleted_article (Invoice)
blob: invoice4_pdf_blob
4 changes: 4 additions & 0 deletions test/fixtures/active_storage/blobs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
invoice1_pdf_blob: <%= ActiveStorage::FixtureSet.blob filename: "invoice_1.pdf", service_name: "test_fixtures" %>
invoice2_pdf_blob: <%= ActiveStorage::FixtureSet.blob filename: "invoice_2.pdf", service_name: "test_fixtures" %>
invoice3_pdf_blob: <%= ActiveStorage::FixtureSet.blob filename: "invoice_3.pdf", service_name: "test_fixtures" %>
invoice4_pdf_blob: <%= ActiveStorage::FixtureSet.blob filename: "invoice_4.pdf", service_name: "test_fixtures" %>
Binary file added test/fixtures/files/invoice_1.pdf
Binary file not shown.
Binary file added test/fixtures/files/invoice_2.pdf
Binary file not shown.
Binary file added test/fixtures/files/invoice_3.pdf
Binary file not shown.
Binary file added test/fixtures/files/invoice_4.pdf
Binary file not shown.
6 changes: 3 additions & 3 deletions test/fixtures/invoices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ sale_ironman_cable_6_months:
price_cents: 200
- quantity: 6
item_name: "Subscription - 1 month"
price_cents: 3000
price_cents: 500
sale_date: "2025-01-20"
invoice_id: 1
issue_date: "2025-01-20"
Expand Down Expand Up @@ -42,7 +42,7 @@ refund_ironman_cable_4_months:
price_cents: 200
- quantity: 4
item_name: "Subscription - 1 month"
price_cents: 2000
price_cents: 500
sale_date: "2025-01-30"
invoice_id: 3
issue_date: "2025-01-30"
Expand All @@ -59,7 +59,7 @@ sale_ironman_deleted_article:
item_name: "Deleted router"
price_cents: 2000
sale_date: "2025-01-21"
invoice_id: 3
invoice_id: 4
issue_date: "2025-01-21"
client_name: "Tony STARK"
payment_date: "2025-01-21T12:02:44.961Z"
Expand Down
Loading