mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
fix generate payment schedule pdf + send by mail
TODO: total amount does not match with sum of all lines - generate invoices for each PS-item - interface to access the payment schedules
This commit is contained in:
parent
12e99f4c9c
commit
e5439901d6
@ -43,4 +43,11 @@ class NotificationsMailer < NotifyWith::NotificationsMailer
|
||||
subject: t('notifications_mailer.notify_member_avoir_ready.subject'),
|
||||
template_name: 'notify_member_avoir_ready')
|
||||
end
|
||||
|
||||
def notify_user_when_payment_schedule_ready
|
||||
attachments[@attached_object.filename] = File.read(@attached_object.file)
|
||||
mail(to: @recipient.email,
|
||||
subject: t('notifications_mailer.notify_member_payment_schedule_ready.subject'),
|
||||
template_name: 'notify_member_payment_schedule_ready')
|
||||
end
|
||||
end
|
||||
|
@ -54,6 +54,7 @@ class NotificationType
|
||||
notify_admins_role_update
|
||||
notify_user_role_update
|
||||
notify_admin_members_stripe_sync
|
||||
notify_user_when_payment_schedule_ready
|
||||
]
|
||||
# deprecated:
|
||||
# - notify_member_subscribed_plan_is_changed
|
||||
|
@ -45,6 +45,10 @@ class PaymentSchedule < PaymentDocument
|
||||
payment_schedule_items.order(due_date: :asc)
|
||||
end
|
||||
|
||||
def user
|
||||
invoicing_profile.user
|
||||
end
|
||||
|
||||
def check_footprint
|
||||
payment_schedule_items.map(&:check_footprint).all? && footprint == compute_footprint
|
||||
end
|
||||
|
@ -79,19 +79,21 @@ class PDF::PaymentSchedule < Prawn::Document
|
||||
payment_schedule.payment_schedule_items.each do |item|
|
||||
|
||||
price = item.amount.to_i / 100.00
|
||||
date = item.due_date
|
||||
date = I18n.l(item.due_date.to_date)
|
||||
|
||||
data += [[date, number_to_currency(price)]]
|
||||
end
|
||||
data += [[I18n.t('payment_schedules.total_amount'), number_to_currency(payment_schedule.total / 100.0)]]
|
||||
|
||||
# display table
|
||||
table(data, header: true, column_widths: [400, 72], cell_style: { inline_format: true }) do
|
||||
row(0).font_style = :bold
|
||||
column(1).style align: :right
|
||||
row(-1).style align: :right
|
||||
row(-1).background_color = 'E4E4E4'
|
||||
row(-1).font_style = :bold
|
||||
font_size(8) do
|
||||
table(data, header: true, column_widths: [400, 72], cell_style: { inline_format: true }) do
|
||||
row(0).font_style = :bold
|
||||
column(1).style align: :right
|
||||
row(-1).style align: :right
|
||||
row(-1).background_color = 'E4E4E4'
|
||||
row(-1).font_style = :bold
|
||||
end
|
||||
end
|
||||
|
||||
# payment method
|
||||
@ -117,7 +119,7 @@ class PDF::PaymentSchedule < Prawn::Document
|
||||
end
|
||||
|
||||
# factice watermark
|
||||
return unless %w[staging test development].include?(invoice.environment)
|
||||
return unless %w[staging test development].include?(payment_schedule.environment)
|
||||
|
||||
transparent(0.1) do
|
||||
rotate(45, origin: [0, 0]) do
|
||||
|
@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
json.title notification.notification_type
|
||||
amount = notification.attached_object.total / 100.0
|
||||
json.description t('.your_schedule_is_ready_html',
|
||||
REFERENCE: notification.attached_object.reference,
|
||||
AMOUNT: number_to_currency(amount),
|
||||
SCHEDULE_ID: notification.attached_object.id)
|
||||
|
@ -0,0 +1,20 @@
|
||||
<%= render 'notifications_mailer/shared/hello', recipient: @recipient %>
|
||||
|
||||
<p>
|
||||
<%= _t('.body.please_find_attached_html',
|
||||
{
|
||||
DATE: I18n.l(@attached_object.created_at.to_date),
|
||||
AMOUNT: number_to_currency(@attached_object.total / 100.0),
|
||||
TYPE: @attached_object.scheduled_type
|
||||
})
|
||||
# messageFormat
|
||||
%>
|
||||
</p>
|
||||
|
||||
<p><%= t('.body.schedule_in_your_dashboard_html',
|
||||
DASHBOARD: link_to(
|
||||
t('.body.your_dashboard'),
|
||||
"#{root_url}#!/dashboard/invoices"
|
||||
)
|
||||
) %>
|
||||
</p>
|
@ -8,13 +8,13 @@ class PaymentScheduleWorker
|
||||
def perform(payment_schedule_id)
|
||||
# generate a payment schedule document
|
||||
ps = PaymentSchedule.find(payment_schedule_id)
|
||||
pdf = ::PDF::PaymentSchedule.new(ps).render # TODO, create ::PDF::PaymentSchedule
|
||||
pdf = ::PDF::PaymentSchedule.new(ps).render
|
||||
|
||||
# save the file on the disk
|
||||
File.binwrite(ps.file, pdf)
|
||||
|
||||
# notify user, send schedule document by email
|
||||
NotificationCenter.call type: 'notify_user_when_invoice_ready', # TODO, create a more appropriate notification type
|
||||
NotificationCenter.call type: 'notify_user_when_payment_schedule_ready',
|
||||
receiver: ps.user,
|
||||
attached_object: ps
|
||||
end
|
||||
|
@ -356,6 +356,8 @@ en:
|
||||
user_NAME_changed_ROLE_html: "User <strong><em>%{NAME}</strong></em> is now %{ROLE}."
|
||||
notify_admin_members_stripe_sync:
|
||||
all_members_sync: "All members were successfully synchronized on Stripe."
|
||||
notify_user_when_payment_schedule_ready:
|
||||
your_schedule_is_ready_html: "Your payment schedule #%{REFERENCE}, of %{AMOUNT}, is ready. <a href='api/payment_schedules/%{SCHEDULE_ID}/download' target='_blank'>Click here to download</a>."
|
||||
#statistics tools for admins
|
||||
statistics:
|
||||
subscriptions: "Subscriptions"
|
||||
|
@ -356,6 +356,8 @@ fr:
|
||||
user_NAME_changed_ROLE_html: "L'utilisateur <strong><em>%{NAME}</strong></em> est maintenant %{ROLE}."
|
||||
notify_admin_members_stripe_sync:
|
||||
all_members_sync: "Tous les membres ont été synchronisés avec succès sur Stripe."
|
||||
notify_user_when_payment_schedule_ready:
|
||||
your_schedule_is_ready_html: "Votre échéancier n°%{REFERENCE}, d'un montant de %{AMOUNT}, est prêt. <a href='api/payment_schedules/%{SCHEDULE_ID}/download' target='_blank'>Cliquez ici pour le télécharger</a>."
|
||||
#statistics tools for admins
|
||||
statistics:
|
||||
subscriptions: "Abonnements"
|
||||
|
@ -287,5 +287,11 @@ en:
|
||||
subject: "Stripe synchronization"
|
||||
body:
|
||||
members_sync: "All members were successfully synchronized on Stripe."
|
||||
notify_member_payment_schedule_ready:
|
||||
subject: "Your payment schedule"
|
||||
body:
|
||||
please_find_attached_html: "Please find attached your payment schedule, issued on {DATE}, with an amount of {AMOUNT} concerning your {TYPE, select, Reservation{reservation} other{subscription}}." #messageFormat interpolation
|
||||
schedule_in_your_dashboard_html: "You can find this payment schedule at any time from %{DASHBOARD} on the Fab Lab's website."
|
||||
your_dashboard: "your dashboard"
|
||||
shared:
|
||||
hello: "Hello %{user_name}"
|
||||
|
@ -287,5 +287,11 @@ fr:
|
||||
subject: "Synchronisation Stripe"
|
||||
body:
|
||||
members_sync: "Tous les membres ont été synchronisés avec succès sur Stripe."
|
||||
notify_member_payment_schedule_ready:
|
||||
subject: "Votre échéancier de paiement"
|
||||
body:
|
||||
please_find_attached_html: "Vous trouverez en pièce jointe votre échéancier de paiement du {DATE}, d'un montant de {AMOUNT} concernant votre {TYPE, select, Reservation{réservation} other{abonnement}}." #messageFormat interpolation
|
||||
schedule_in_your_dashboard_html: "Vous pouvez à tout moment retrouver votre échéancier dans %{DASHBOARD} sur le site du Fab Lab."
|
||||
your_dashboard: "votre tableau de bord"
|
||||
shared:
|
||||
hello: "Bonjour %{user_name}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user