mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-19 13:54:25 +01:00
configure invoices prefix from the DB
This commit is contained in:
parent
b66cb5d334
commit
48bcf0b838
@ -55,9 +55,10 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
|
||||
|
||||
// Invoice PDF filename settings (and example)
|
||||
$scope.file = {
|
||||
prefix: 'Fablab_demo-facture',
|
||||
prefix: settings.invoice_prefix,
|
||||
nextId: 40,
|
||||
date: moment().format('DDMMYYYY')
|
||||
date: moment().format('DDMMYYYY'),
|
||||
templateUrl: 'editPrefix.html'
|
||||
}
|
||||
|
||||
// Invoices parameters
|
||||
@ -484,6 +485,38 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Open a modal dialog allowing the user to edit the prefix of the invoice file name
|
||||
*/
|
||||
$scope.openEditPrefix = function () {
|
||||
const modalInstance = $uibModal.open({
|
||||
animation: true,
|
||||
templateUrl: $scope.file.templateUrl,
|
||||
size: 'lg',
|
||||
resolve: {
|
||||
model () { return $scope.file.prefix;}
|
||||
},
|
||||
controller: ['$scope', '$uibModalInstance', 'model', function ($scope, $uibModalInstance, model) {
|
||||
$scope.model = model;
|
||||
$scope.ok = function () { $uibModalInstance.close($scope.model); };
|
||||
$scope.cancel = function () { $uibModalInstance.dismiss('cancel'); };
|
||||
}]
|
||||
});
|
||||
|
||||
return modalInstance.result.then(function (model) {
|
||||
Setting.update({ name: 'invoice_prefix' }, { value: model }, function (data) {
|
||||
$scope.file.prefix = model;
|
||||
return growl.success(_t('app.admin.invoices.prefix_successfully_saved'));
|
||||
}
|
||||
, function (error) {
|
||||
if (error.status === 304) return;
|
||||
|
||||
growl.error(_t('app.admin.invoices.an_error_occurred_while_saving_the_prefix'));
|
||||
console.error(error);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback to save the value of the text zone when editing is done
|
||||
*/
|
||||
|
@ -839,7 +839,7 @@ angular.module('application.router', ['ui.router'])
|
||||
'accounting_VAT_code', 'accounting_VAT_label', 'accounting_subscription_code', 'accounting_subscription_label', \
|
||||
'accounting_Machine_code', 'accounting_Machine_label', 'accounting_Training_code', 'accounting_Training_label', \
|
||||
'accounting_Event_code', 'accounting_Event_label', 'accounting_Space_code', 'accounting_Space_label', \
|
||||
'feature_tour_display', 'online_payment_module', 'stripe_public_key', 'stripe_currency']` }).$promise;
|
||||
'feature_tour_display', 'online_payment_module', 'stripe_public_key', 'stripe_currency', 'invoice_prefix']` }).$promise;
|
||||
}],
|
||||
stripeSecretKey: ['Setting', function (Setting) { return Setting.isPresent({ name: 'stripe_secret_key' }).$promise; }],
|
||||
onlinePaymentStatus: ['Payment', function (Payment) { return Payment.onlinePaymentStatus().$promise; }],
|
||||
|
@ -2,10 +2,6 @@
|
||||
<i class="fa fa-warning m-r"></i>
|
||||
<span translate>{{ 'app.admin.invoices.warning_invoices_disabled' }}</span>
|
||||
</div>
|
||||
<div class="invoice-file">
|
||||
<i class="fa fa-file-pdf-o" aria-hidden="true"></i>
|
||||
<span class="filename"><span class="prefix">{{file.prefix}}</span>-{{file.nextId}}_{{file.date}}.pdf</span>
|
||||
</div>
|
||||
<form class="invoice-placeholder">
|
||||
<div class="invoice-logo">
|
||||
<img src="data:image/png;base64," data-src="holder.js/100%x100%/text:/font:FontAwesome/icon" bs-holder ng-if="!invoice.logo" class="img-responsive">
|
||||
@ -91,6 +87,11 @@
|
||||
ng-blur="legalsEditEnd($event)">
|
||||
</div>
|
||||
</form>
|
||||
<div class="invoice-file">
|
||||
<h3 class="m-l" translate>{{ 'app.admin.invoices.filename' }}</h3>
|
||||
<i class="fa fa-file-pdf-o" aria-hidden="true"></i>
|
||||
<span class="filename"><span class="prefix" ng-click="openEditPrefix()">{{file.prefix}}</span>-{{file.nextId}}_{{file.date}}.pdf</span>
|
||||
</div>
|
||||
|
||||
|
||||
<script type="text/ng-template" id="editReference.html">
|
||||
@ -312,3 +313,27 @@
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/ng-template" id="editPrefix.html">
|
||||
<div class="custom-invoice">
|
||||
<div class="modal-header">
|
||||
<h3 class="modal-title" translate>{{ 'app.admin.invoices.filename' }}</h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<p class="alert alert-info m-h-md" translate>
|
||||
{{ 'app.admin.invoices.prefix_info' }}
|
||||
</p>
|
||||
<div>
|
||||
<div class="model">
|
||||
<label for="prefix" translate>{{ 'app.admin.invoices.prefix' }}</label>
|
||||
<input type="text" id="prefix" class="form-control" ng-model="model">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-warning" ng-click="ok()" translate>{{ 'app.shared.buttons.confirm' }}</button>
|
||||
<button class="btn btn-default" ng-click="cancel()" translate>{{ 'app.shared.buttons.cancel' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</script>
|
||||
|
@ -40,7 +40,13 @@ class Invoice < ApplicationRecord
|
||||
end
|
||||
|
||||
def filename
|
||||
"#{ENV['INVOICE_PREFIX']}-#{id}_#{created_at.strftime('%d%m%Y')}.pdf"
|
||||
prefix = Setting.find_by(name: 'invoice_prefix').history_values.order(created_at: :desc).where('created_at <= ?', created_at).limit(1).first
|
||||
prefix ||= if created_at < Setting.find_by(name: 'invoice_prefix').history_values.order(created_at: :asc).limit(1).first.created_at
|
||||
Setting.find_by(name: 'invoice_prefix').history_values.order(created_at: :asc).limit(1).first
|
||||
else
|
||||
Setting.find_by(name: 'invoice_prefix')..history_values.order(created_at: :desc).limit(1).first
|
||||
end
|
||||
"#{prefix.value}-#{id}_#{created_at.strftime('%d%m%Y')}.pdf"
|
||||
end
|
||||
|
||||
def user
|
||||
|
@ -99,7 +99,8 @@ class Setting < ApplicationRecord
|
||||
online_payment_module
|
||||
stripe_public_key
|
||||
stripe_secret_key
|
||||
stripe_currency] }
|
||||
stripe_currency
|
||||
invoice_prefix] }
|
||||
# WARNING: when adding a new key, you may also want to add it in app/policies/setting_policy.rb#public_whitelist
|
||||
|
||||
def value
|
||||
|
@ -522,6 +522,11 @@ en:
|
||||
an_error_occurred_while_saving_the_address_and_the_legal_information: "An error occurred while saving the address and the legal information."
|
||||
logo_successfully_saved: "Logo successfully saved."
|
||||
an_error_occurred_while_saving_the_logo: "An error occurred while saving the logo."
|
||||
filename: "File name"
|
||||
prefix_info: "The invoices will be generated as PDF files, named with the following prefix."
|
||||
prefix: "Prefix"
|
||||
prefix_successfully_saved: "File prefix successfully saved"
|
||||
an_error_occurred_while_saving_the_prefix: "An error occurred while saving the file prefix"
|
||||
online_payment: "Online payment"
|
||||
close_accounting_period: "Close an accounting period"
|
||||
close_from_date: "Close from"
|
||||
@ -677,7 +682,7 @@ en:
|
||||
administrator_successfully_deleted: "Administrator successfully deleted."
|
||||
unable_to_delete_the_administrator: "Unable to delete the administrator."
|
||||
changes_successfully_saved: "Changes successfully saved."
|
||||
an_error_occurred_while_saving_changes: "An error occurred when saving changes."
|
||||
an__occurr_occurred_while_saving_changes: "An error occurred when saving changes."
|
||||
export_is_running_you_ll_be_notified_when_its_ready: "Export is running. You'll be notified when it's ready."
|
||||
tag_form:
|
||||
tags: "Tags"
|
||||
|
@ -522,6 +522,11 @@ fr:
|
||||
an_error_occurred_while_saving_the_address_and_the_legal_information: "Une erreur est survenue lors de l'enregistrement de l'adresse et des informations légales."
|
||||
logo_successfully_saved: "Le logo bien été enregistré."
|
||||
an_error_occurred_while_saving_the_logo: "Une erreur est survenue lors de l'enregistrement du logo."
|
||||
filename: "Nom de fichier"
|
||||
prefix_info: "Les factures seront générées sous la forme de fichiers PDF, nommés avec le préfixe suivant."
|
||||
prefix: "Préfixe"
|
||||
prefix_successfully_saved: "Le préfixe de fichier a bien été enregistré"
|
||||
an_error_occurred_while_saving_the_prefix: "Une erreur est survenue lors de l'enregistrement du préfixe de fichier"
|
||||
online_payment: "Paiement en ligne"
|
||||
close_accounting_period: "Clôturer une période comptable"
|
||||
close_from_date: "Clôturer depuis"
|
||||
|
@ -882,6 +882,8 @@ end
|
||||
|
||||
Setting.set('stripe_currency', 'EUR') unless Setting.find_by(name: 'stripe_currency').try(:value)
|
||||
|
||||
Setting.set('invoice_prefix', 'FabManager_invoice') unless Setting.find_by(name: 'invoice_prefix').try(:value)
|
||||
|
||||
if StatisticCustomAggregation.count.zero?
|
||||
# available reservations hours for machines
|
||||
machine_hours = StatisticType.find_by(key: 'hour', statistic_index_id: 2)
|
||||
|
@ -51,18 +51,6 @@ When using docker-compose, you should provide the name of the service in your [d
|
||||
Used by the authentication system to generate random tokens, eg. for resetting passwords.
|
||||
Used by Rails to verify the integrity of signed cookies.
|
||||
You can generate such a random key by running `rails secret`.
|
||||
<a name="INVOICE_PREFIX"></a>
|
||||
|
||||
INVOICE_PREFIX
|
||||
|
||||
When payments are done on the platform, an invoice will be generated as a PDF file.
|
||||
The PDF file name will be of the form "(INVOICE_PREFIX) - (invoice ID) _ (invoice date) .pdf".
|
||||
<a name="FABLAB_WITHOUT_ONLINE_PAYMENT"></a>
|
||||
|
||||
FABLAB_WITHOUT_ONLINE_PAYMENT
|
||||
|
||||
If set to 'true', the online payment won't be available and the you'll be only able to process reservations when logged as admin.
|
||||
Valid stripe API keys are still required, even if you don't require online payments.
|
||||
<a name="FABLAB_WITHOUT_WALLET"></a>
|
||||
|
||||
FABLAB_WITHOUT_WALLET
|
||||
@ -132,7 +120,7 @@ The check will run every weeks and if the threshold is exceeded, an alert will b
|
||||
ADMIN_EMAIL, ADMIN_PASSWORD
|
||||
|
||||
Credentials for the first admin user created when seeding the project.
|
||||
By default, theses variables are not present in application.yml because they are only used once, when running the database seed with the command `rails db:seed`.
|
||||
By default, these variables are not present in the env file, because they are only used once, when running the database seed with the command `rails db:seed`.
|
||||
<a name="SUPERADMIN_EMAIL"></a>
|
||||
|
||||
SUPERADMIN_EMAIL
|
||||
|
@ -8,12 +8,7 @@ ELASTICSEARCH_HOST=fabmanager-elastic
|
||||
|
||||
SECRET_KEY_BASE=83daf5e7b80d990f037407bab78dff9904aaf3c195a50f84fa8695a22287e707dfbd9524b403b1dcf116ae1d8c06844c3d7ed942564e5b46be6ae3ead93a9d30
|
||||
|
||||
# Invoices
|
||||
INVOICE_PREFIX=Demo-FabLab_facture
|
||||
|
||||
# FabLab optional modules
|
||||
FABLAB_WITHOUT_ONLINE_PAYMENT=false
|
||||
PHONE_REQUIRED=true
|
||||
# FabLab optional modules=
|
||||
FABLAB_WITHOUT_WALLET=false
|
||||
|
||||
USER_CONFIRMATION_NEEDED_TO_SIGN_IN=false
|
||||
|
@ -129,7 +129,8 @@ namespace :fablab do
|
||||
%w[! FABLAB_WITHOUT_ONLINE_PAYMENT online_payment_module false],
|
||||
%w[_ STRIPE_PUBLISHABLE_KEY stripe_public_key],
|
||||
%w[_ STRIPE_API_KEY stripe_secret_key],
|
||||
%w[_ STRIPE_CURRENCY stripe_currency]
|
||||
%w[_ STRIPE_CURRENCY stripe_currency],
|
||||
%w[_ INVOICE_PREFIX invoice_prefix FabManager_invoice]
|
||||
]
|
||||
|
||||
mapping.each do |m|
|
||||
|
@ -4,9 +4,6 @@ ELASTICSEARCH_HOST=elasticsearch
|
||||
|
||||
SECRET_KEY_BASE=
|
||||
|
||||
INVOICE_PREFIX=Demo-FabLab_facture
|
||||
FABLAB_WITHOUT_ONLINE_PAYMENT=false
|
||||
PHONE_REQUIRED=false
|
||||
FABLAB_WITHOUT_WALLET=false
|
||||
|
||||
SLOT_DURATION=60
|
||||
|
@ -234,7 +234,7 @@ configure_env_file()
|
||||
|
||||
local doc variables secret
|
||||
doc=$(\curl -sSL https://raw.githubusercontent.com/sleede/fab-manager/master/doc/environment.md)
|
||||
variables=(INVOICE_PREFIX FABLAB_WITHOUT_ONLINE_PAYMENT FABLAB_WITHOUT_WALLET \
|
||||
variables=(FABLAB_WITHOUT_WALLET \
|
||||
USER_CONFIRMATION_NEEDED_TO_SIGN_IN DEFAULT_HOST DEFAULT_PROTOCOL DELIVERY_METHOD SMTP_ADDRESS SMTP_PORT SMTP_USER_NAME SMTP_PASSWORD SMTP_AUTHENTICATION \
|
||||
SMTP_ENABLE_STARTTLS_AUTO SMTP_OPENSSL_VERIFY_MODE SMTP_TLS \
|
||||
LOG_LEVEL MAX_IMAGE_SIZE MAX_CAO_SIZE MAX_IMPORT_SIZE DISK_SPACE_MB_ALERT \
|
||||
|
8
test/fixtures/history_values.yml
vendored
8
test/fixtures/history_values.yml
vendored
@ -661,3 +661,11 @@ history_value_69:
|
||||
value: usd
|
||||
created_at: 2020-06-08 17:12:16.846525000 Z
|
||||
updated_at: 2020-06-08 17:12:16.846525000 Z
|
||||
|
||||
history_value_70:
|
||||
id: 70
|
||||
setting_id: 70
|
||||
value: 1
|
||||
name: FabManager_invoice
|
||||
created_at: 2020-06-15 10:04:06.216541000 Z
|
||||
updated_at: 2020-06-15 10:04:06.216541000 Z
|
||||
|
6
test/fixtures/settings.yml
vendored
6
test/fixtures/settings.yml
vendored
@ -406,3 +406,9 @@ setting_69:
|
||||
name: stripe_currency
|
||||
created_at: 2020-06-08 17:12:16.846525000 Z
|
||||
updated_at: 2020-06-08 17:12:16.846525000 Z
|
||||
|
||||
setting_70:
|
||||
id: 70
|
||||
name: invoice_prefix
|
||||
created_at: 2020-06-15 10:04:06.216541000 Z
|
||||
updated_at: 2020-06-15 10:04:06.216541000 Z
|
||||
|
Loading…
x
Reference in New Issue
Block a user