1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-01-18 07:52:23 +01:00

fix cancel schedule

This commit is contained in:
Sylvain 2021-02-09 16:26:09 +01:00
parent ff0c69fc58
commit f3ad59d33a
5 changed files with 31 additions and 18 deletions

View File

@ -18,7 +18,7 @@ import stripeLogo from '../../../images/powered_by_stripe.png';
import mastercardLogo from '../../../images/mastercard.png';
import visaLogo from '../../../images/visa.png';
import { StripeCardUpdate } from './stripe-card-update';
import { User } from '../models/user';
import { User, UserRole } from '../models/user';
declare var Fablab: IFablab;
@ -131,6 +131,13 @@ const PaymentSchedulesTableComponent: React.FC<PaymentSchedulesTableProps> = ({
return <span className={`state-${item.state}`}>{res}</span>;
}
/**
* Check if the current operator has administrative rights or is a normal member
*/
const isPrivileged = (): boolean => {
return (operator.role === UserRole.Admin || operator.role == UserRole.Manager);
}
/**
* Return the action button(s) for the given deadline
*/
@ -139,12 +146,16 @@ const PaymentSchedulesTableComponent: React.FC<PaymentSchedulesTableProps> = ({
case PaymentScheduleItemState.Paid:
return downloadButton(TargetType.Invoice, item.invoice_id);
case PaymentScheduleItemState.Pending:
return (
<FabButton onClick={handleConfirmCheckPayment(item)}
icon={<i className="fas fa-money-check" />}>
{t('app.admin.invoices.schedules_table.confirm_payment')}
</FabButton>
);
if (isPrivileged()) {
return (
<FabButton onClick={handleConfirmCheckPayment(item)}
icon={<i className="fas fa-money-check" />}>
{t('app.admin.invoices.schedules_table.confirm_payment')}
</FabButton>
);
} else {
return <span>{t('app.admin.invoices.schedules_table.please_ask_reception')}</span>
}
case PaymentScheduleItemState.RequireAction:
return (
<FabButton onClick={handleSolveAction(item)}
@ -160,12 +171,16 @@ const PaymentSchedulesTableComponent: React.FC<PaymentSchedulesTableProps> = ({
</FabButton>
);
case PaymentScheduleItemState.Error:
return (
<FabButton onClick={handleCancelSubscription(schedule)}
icon={<i className="fas fa-times" />}>
{t('app.admin.invoices.schedules_table.cancel_subscription')}
</FabButton>
)
if (isPrivileged()) {
return (
<FabButton onClick={handleCancelSubscription(schedule)}
icon={<i className="fas fa-times" />}>
{t('app.admin.invoices.schedules_table.cancel_subscription')}
</FabButton>
)
} else {
return <span>{t('app.admin.invoices.schedules_table.please_ask_reception')}</span>
}
default:
return <span />
}

View File

@ -37,10 +37,6 @@ class Subscription < ApplicationRecord
generate_invoice(operator_profile_id).save
end
def cancel
update_columns(canceled_at: DateTime.current)
end
def expire(time)
if !expired?
update_columns(expiration_date: time, canceled_at: time)

View File

@ -147,7 +147,7 @@ class PaymentScheduleService
end
# cancel subscription
subscription = Subscription.find(payment_schedule.payment_schedule_items.first.details['subscription_id'])
subscription.cancel
subscription.expire(DateTime.current)
subscription.canceled_at
end

View File

@ -673,6 +673,7 @@ en:
validate_button: "Validate the new card"
cancel_subscription: "Cancel the subscription"
confirm_cancel_subscription: "You're about to cancel this payment schedule and the related subscription. Are you sure?"
please_ask_reception: "For any questions, please contact the FabLab's reception."
document_filters:
reference: "Reference"
customer: "Customer"

View File

@ -673,6 +673,7 @@ fr:
validate_button: "Valider la nouvelle carte"
cancel_subscription: "Annuler l'abonnement"
confirm_cancel_subscription: "Vous êtes sur le point d'annuler cet échéancier de paiement ainsi que l'abonnement lié. Êtes-vous sur ?"
please_ask_reception: "Pour toute question, merci de contacter l'accueil du FabLab."
document_filters:
reference: "Référence"
customer: "Client"