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

improved accounting codes settings page (1 click saves all) + improved export file name

This commit is contained in:
Sylvain 2019-09-16 14:39:47 +02:00
parent 6a0aeb2717
commit 02d28e0b8c
17 changed files with 132 additions and 106 deletions

View File

@ -82,13 +82,21 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
name: 'accounting_journal_code',
value: settings['accounting_journal_code']
},
clientCode: {
name: 'accounting_client_code',
value: settings['accounting_client_code']
cardClientCode: {
name: 'accounting_card_client_code',
value: settings['accounting_card_client_code']
},
clientLabel: {
name: 'accounting_client_label',
value: settings['accounting_client_label']
cardClientLabel: {
name: 'accounting_card_client_label',
value: settings['accounting_card_client_label']
},
siteClientCode: {
name: 'accounting_site_client_code',
value: settings['accounting_site_client_code']
},
siteClientLabel: {
name: 'accounting_site_client_label',
value: settings['accounting_site_client_label']
},
walletCode: {
name: 'accounting_wallet_code',
@ -535,14 +543,12 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
}
/**
* Callback to save the setting value to the database
* @param setting {{value:*, name:string}} note that the value will be stringified
* Callback to bulk save all settings in the page to the database with their values
*/
$scope.save = function(setting) {
Setting.update(
{ name: setting.name },
{ value: setting.value },
function () { growl.success(_t('invoices.customization_of_SETTING_successfully_saved', { SETTING: _t(`invoices.${setting.name}`) })); },
$scope.save = function() {
Setting.bulkUpdate(
{ settings: Object.values($scope.settings) },
function () { growl.success(_t('invoices.codes_customization_success')); },
function (error) { console.log(error); }
);
}
@ -1010,12 +1016,12 @@ Application.Controllers.controller('AccountingExportModalController', ['$scope',
/**
* Prepare the query for the export API
* @returns {{extension: *, query: *, category: string, type: string, key: *}}
* @returns {{extension: *, query: *, category: string, type: *, key: *}}
*/
const mkQuery = function() {
return {
category: 'accounting',
type: 'accounting-software',
type: $scope.exportTarget.software,
extension: $scope.exportTarget.settings.format,
key: $scope.exportTarget.settings.separator,
query: JSON.stringify({

View File

@ -9,6 +9,10 @@ Application.Services.factory('Setting', ['$resource', function ($resource) {
return angular.toJson({ setting: data });
}
},
bulkUpdate: {
url: '/api/settings/bulk_update',
method: 'PATCH'
},
query: {
isArray: false
}

View File

@ -82,6 +82,7 @@
<input name="authenticity_token" type="hidden" ng-value="csrfToken"/>
<input name="_method" type="hidden" ng-value="method"/>
<input name="extension" type="hidden" ng-value="query.extension"/>
<input name="type" type="hidden" ng-value="exportTarget.software"/>
<input name="key" type="hidden" ng-value="query.key"/>
<input name="query" type="hidden" ng-value="query.query"/>
<input type="submit" class="btn btn-warning" value="{{ 'confirm' | translate }}" formtarget="export-frame"/>

View File

@ -214,117 +214,99 @@
<div class="col-md-6">
<label for="journalCode" translate>{{ 'invoices.accounting_journal_code' }}</label>
<input type="text" id="journalCode" ng-model="settings.journalCode.value" class="form-control" placeholder="{{ 'invoices.general_journal_code' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.journalCode)" translate>{{ 'save' }}</button>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label for="clientCode" translate>{{ 'invoices.accounting_client_code' }}</label>
<input type="text" id="clientCode" ng-model="settings.clientCode.value" class="form-control" placeholder="{{ 'invoices.general_client_code' | translate }}" />
<button name="button" class="btn btn-warning" ng-click="save(settings.clientCode)" translate>{{ 'save' }}</button>
<div class="col-md-6">
<label for="cardClientCode" translate>{{ 'invoices.accounting_card_client_code' }}</label>
<input type="text" id="cardClientCode" ng-model="settings.cardClientCode.value" class="form-control" placeholder="{{ 'invoices.card_client_code' | translate }}" />
</div>
<div class="col-md-4">
<label for="clientLabel" translate>{{ 'invoices.accounting_client_label' }}</label>
<input type="text" id="clientLabel" ng-model="settings.clientLabel.value" class="form-control" placeholder="{{ 'invoices.general_client_label' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.clientLabel)" translate>{{ 'save' }}</button>
<div class="col-md-6">
<label for="cardClientLabel" translate>{{ 'invoices.accounting_card_client_label' }}</label>
<input type="text" id="cardClientLabel" ng-model="settings.cardClientLabel.value" class="form-control" placeholder="{{ 'invoices.card_client_label' | translate }}"/>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="col-md-6">
<label for="siteClientCode" translate>{{ 'invoices.accounting_site_client_code' }}</label>
<input type="text" id="siteClientCode" ng-model="settings.siteClientCode.value" class="form-control" placeholder="{{ 'invoices.site_client_code' | translate }}" />
</div>
<div class="col-md-6">
<label for="siteClientLabel" translate>{{ 'invoices.accounting_site_client_label' }}</label>
<input type="text" id="siteClientLabel" ng-model="settings.siteClientLabel.value" class="form-control" placeholder="{{ 'invoices.site_client_label' | translate }}"/>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label for="walletCode" translate>{{ 'invoices.accounting_wallet_code' }}</label>
<input type="text" id="walletCode" ng-model="settings.walletCode.value" class="form-control" placeholder="{{ 'invoices.general_wallet_code' | translate }}" />
<button name="button" class="btn btn-warning" ng-click="save(settings.walletCode)" translate>{{ 'save' }}</button>
</div>
<div class="col-md-4">
<div class="col-md-6">
<label for="walletLabel" translate>{{ 'invoices.accounting_wallet_label' }}</label>
<input type="text" id="walletLabel" ng-model="settings.walletLabel.value" class="form-control" placeholder="{{ 'invoices.general_wallet_label' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.walletLabel)" translate>{{ 'save' }}</button>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="col-md-6">
<label for="vatCode" translate>{{ 'invoices.accounting_vat_code' }}</label>
<input type="text" id="vatCode" ng-model="settings.vatCode.value" class="form-control" placeholder="{{ 'invoices.general_vat_code' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.vatCode)" translate>{{ 'save' }}</button>
</div>
<div class="col-md-4">
<div class="col-md-6">
<label for="vatLabel" translate>{{ 'invoices.accounting_vat_label' }}</label>
<input type="text" id="vatLabel" ng-model="settings.vatLabel.value" class="form-control" placeholder="{{ 'invoices.general_vat_label' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.vatLabel)" translate>{{ 'save' }}</button>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="col-md-6">
<label for="subscriptionCode" translate>{{ 'invoices.accounting_subscription_code' }}</label>
<input type="text" id="subscriptionCode" ng-model="settings.subscriptionCode.value" class="form-control" placeholder="{{ 'invoices.general_subscription_code' | translate }}" />
<button name="button" class="btn btn-warning" ng-click="save(settings.subscriptionCode)" translate>{{ 'save' }}</button>
</div>
<div class="col-md-4">
<div class="col-md-6">
<label for="subscriptionLabel" translate>{{ 'invoices.accounting_subscription_label' }}</label>
<input type="text" id="subscriptionLabel" ng-model="settings.subscriptionLabel.value" class="form-control" placeholder="{{ 'invoices.general_subscription_label' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.subscriptionLabel)" translate>{{ 'save' }}</button>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="col-md-6">
<label for="machineCode" translate>{{ 'invoices.accounting_Machine_code' }}</label>
<input type="text" id="machineCode" ng-model="settings.machineCode.value" class="form-control" placeholder="{{ 'invoices.general_machine_code' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.machineCode)" translate>{{ 'save' }}</button>
</div>
<div class="col-md-4">
<div class="col-md-6">
<label for="machineLabel" translate>{{ 'invoices.accounting_Machine_label' }}</label>
<input type="text" id="machineLabel" ng-model="settings.machineLabel.value" class="form-control" placeholder="{{ 'invoices.general_machine_label' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.machineLabel)" translate>{{ 'save' }}</button>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="col-md-6">
<label for="trainingCode" translate>{{ 'invoices.accounting_Training_code' }}</label>
<input type="text" id="trainingCode" ng-model="settings.trainingCode.value" class="form-control" placeholder="{{ 'invoices.general_training_code' | translate }}" />
<button name="button" class="btn btn-warning" ng-click="save(settings.trainingCode)" translate>{{ 'save' }}</button>
</div>
<div class="col-md-4">
<div class="col-md-6">
<label for="trainingLabel" translate>{{ 'invoices.accounting_Training_label' }}</label>
<input type="text" id="trainingLabel" ng-model="settings.trainingLabel.value" class="form-control" placeholder="{{ 'invoices.general_training_label' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.trainingLabel)" translate>{{ 'save' }}</button>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="col-md-6">
<label for="eventCode" translate>{{ 'invoices.accounting_Event_code' }}</label>
<input type="text" id="eventCode" ng-model="settings.eventCode.value" class="form-control" placeholder="{{ 'invoices.general_event_code' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.eventCode)" translate>{{ 'save' }}</button>
</div>
<div class="col-md-4">
<div class="col-md-6">
<label for="eventLabel" translate>{{ 'invoices.accounting_Event_label' }}</label>
<input type="text" id="eventLabel" ng-model="settings.eventLabel.value" class="form-control" placeholder="{{ 'invoices.general_event_label' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.eventLabel)" translate>{{ 'save' }}</button>
</div>
</div>
<div class="row">
<div class="col-md-4">
<div class="col-md-6">
<label for="spaceCode" translate>{{ 'invoices.accounting_Space_code' }}</label>
<input type="text" id="spaceCode" ng-model="settings.spaceCode.value" class="form-control" placeholder="{{ 'invoices.general_space_code' | translate }}" />
<button name="button" class="btn btn-warning" ng-click="save(settings.spaceCode)" translate>{{ 'save' }}</button>
</div>
<div class="col-md-4">
<div class="col-md-6">
<label for="spaceLabel" translate>{{ 'invoices.accounting_Space_label' }}</label>
<input type="text" id="spaceLabel" ng-model="settings.spaceLabel.value" class="form-control" placeholder="{{ 'invoices.general_space_label' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.spaceLabel)" translate>{{ 'save' }}</button>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label for="couponCode" translate>{{ 'invoices.accounting_coupon_code' }}</label>
<input type="text" id="couponCode" ng-model="settings.couponCode.value" class="form-control" placeholder="{{ 'invoices.general_coupon_code' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.couponCode)" translate>{{ 'save' }}</button>
</div>
<div class="col-md-4">
<label for="couponLabel" translate>{{ 'invoices.accounting_coupon_label' }}</label>
<input type="text" id="couponLabel" ng-model="settings.couponLabel.value" class="form-control" placeholder="{{ 'invoices.general_coupon_label' | translate }}"/>
<button name="button" class="btn btn-warning" ng-click="save(settings.couponLabel)" translate>{{ 'save' }}</button>
</div>
</div>
<button name="button" class="btn btn-warning m-t-lg" ng-click="save()" translate>{{ 'save' }}</button>
</div>
</div>
</uib-tab>

View File

@ -15,7 +15,7 @@ class API::AccountingExportsController < API::ApiController
if export.nil? || !FileTest.exist?(export.file)
@export = Export.new(
category: 'accounting',
export_type: 'accounting-software',
export_type: params[:type],
user: current_user,
extension: params[:extension],
query: params[:query],

View File

@ -68,7 +68,7 @@ class API::ExportsController < API::ApiController
end
when 'accounting'
case type
when 'accounting-software'
when 'acd'
export = export.where('created_at > ?', Invoice.maximum('updated_at'))
else
raise ArgumentError, "Unknown type accounting/#{type}"

View File

@ -18,6 +18,19 @@ class API::SettingsController < API::ApiController
end
end
def bulk_update
authorize Setting
@settings = []
params[:settings].each do |setting|
next if !setting[:name] || !setting[:value]
db_setting = Setting.find_or_initialize_by(name: setting[:name])
db_setting.save && db_setting.history_values.create(value: setting[:value], invoicing_profile: current_user.invoicing_profile)
@settings.push db_setting
end
end
def show
@setting = Setting.find_or_create_by(name: params[:name])
@show_history = params[:history] == 'true' && current_user.admin?

View File

@ -1,5 +1,8 @@
# frozen_string_literal: true
# Check the access policies for API::SettingsController
class SettingPolicy < ApplicationPolicy
%w(update).each do |action|
%w[update bulk_update].each do |action|
define_method "#{action}?" do
user.admin?
end

View File

@ -70,7 +70,7 @@ class AccountingExportService
when 'piece'
row << invoice.reference
when 'line_label'
row << label(invoice.invoicing_profile.full_name)
row << label(invoice.invoicing_profile&.full_name)
when 'debit_origin'
row << debit_client(invoice, total)
when 'credit_origin'

View File

@ -0,0 +1,11 @@
# frozen_string_literal: true
@settings.each do |setting|
if setting[:errors]
json.error setting.errors.full_messages
json.id setting.id
json.name setting.name
else
json.partial! 'api/settings/setting', setting: setting
end
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
@settings.each do |setting|
json.set! setting.name, setting.value
end

View File

@ -1,3 +1,5 @@
# frozen_string_literal: true
json.setting do
json.partial! 'api/settings/setting', setting: @setting
end

View File

@ -435,10 +435,14 @@ en:
accounting_codes: "Accounting codes"
accounting_journal_code: "Journal code"
general_journal_code: "Journal code"
accounting_client_code: "Customers code"
general_client_code: "Accounting code for all customers"
accounting_client_label: "Customers label"
general_client_label: "Account label for all customers"
accounting_card_client_code: "Card clients code"
card_client_code: "Accounting code for clients who paid by card"
accounting_card_client_label: "Card clients label"
card_client_label: "Account label for clients who paid by card"
accounting_site_client_code: "On site client code"
site_client_code: "Accounting code for clients who paid on site"
accounting_site_client_label: "On site client label"
site_client_label: "Accounting label for clients who paid on site"
accounting_wallet_code: "Wallet code"
general_wallet_code: "Accounting code for wallet credit"
accounting_wallet_label: "Wallet label"
@ -467,11 +471,7 @@ en:
general_space_code: "Accounting code for all spaces"
accounting_Space_label: "Spaces label"
general_space_label: "Account label for all spaces"
accounting_coupon_code: "Coupons code"
general_coupon_code: "Accounting code for all coupons"
accounting_coupon_label: "Coupons label"
general_coupon_label: "Account label for all coupons"
customization_of_SETTING_successfully_saved: "Customization of the {{SETTING}} successfully saved." # angular interpolation
codes_customization_success: "Customization of the accounting codes successfully saved."
export_accounting_data: "Export accounting data"
export_to: "Export to the accounting software"
export_is_running: "Export is running. You'll be notified when it's ready."

View File

@ -435,10 +435,14 @@ es:
accounting_codes: "Accounting codes" # translation_missing
accounting_journal_code: "Journal code" # translation_missing
general_journal_code: "Journal code" # translation_missing
accounting_client_code: "Customers code" # translation_missing
general_client_code: "Accounting code for all customers" # translation_missing
accounting_client_label: "Customers label" # translation_missing
general_client_label: "Account label for all customers" # translation_missing
accounting_card_client_code: "Card clients code" # translation_missing
card_client_code: "Accounting code for clients who paid by card" # translation_missing
accounting_card_client_label: "Card clients label" # translation_missing
card_client_label: "Account label for clients who paid by card" # translation_missing
accounting_site_client_code: "On site client code" # translation_missing
site_client_code: "Accounting code for clients who paid on site" # translation_missing
accounting_site_client_label: "On site client label" # translation_missing
site_client_label: "Accounting label for clients who paid on site" # translation_missing
accounting_wallet_code: "Wallet code" # translation_missing
general_wallet_code: "Accounting code for wallet credit" # translation_missing
accounting_wallet_label: "Wallet label" # translation_missing
@ -467,11 +471,7 @@ es:
general_space_code: "Accounting code for all spaces" # translation_missing
accounting_Space_label: "Spaces label" # translation_missing
general_space_label: "Account label for all spaces" # translation_missing
accounting_coupon_code: "Coupons code" # translation_missing
general_coupon_code: "Accounting code for all coupons" # translation_missing
accounting_coupon_label: "Coupons label" # translation_missing
general_coupon_label: "Account label for all coupons" # translation_missing
customization_of_SETTING_successfully_saved: "Customization of the {{SETTING}} successfully saved." # angular interpolation # translation_missing
codes_customization_success: "Customization of accounting codes successfully saved." # angular interpolation # translation_missing
export_accounting_data: "Export accounting data" # translation_missing
export_to: "Export to the accounting software" # translation_missing
export_is_running: "Exportando, será notificado cuando esté listo."

View File

@ -435,10 +435,14 @@ fr:
accounting_codes: "Codes comptables"
accounting_journal_code: "Code journal"
general_journal_code: "Code journal"
accounting_client_code: "Code clients"
general_client_code: "Code comptable pour tous les clients"
accounting_client_label: "Libellé client"
general_client_label: "Libellé du compte pour tous les clients"
accounting_card_client_code: "Code clients par carte"
card_client_code: "Code comptable pour les clients ayant réglé par carte bancaire"
accounting_card_client_label: "Libellé clients par carte"
card_client_label: "Libellé du compte pour les clients ayant réglé par carte bancaire"
accounting_site_client_code: "Code clients à l'accueil"
site_client_code: "Code comptable pour les clients ayant réglé à l'accueil"
accounting_site_client_label: "Libellé clients à l'accueil"
site_client_label: "Libellé du compte pour les clients ayant réglé à l'accueil"
accounting_wallet_code: "Code porte-monnaie"
general_wallet_code: "Code comptable pour le crédit du porte-monnaie"
accounting_wallet_label: "Libellé porte-monnaie"
@ -451,7 +455,7 @@ fr:
general_subscription_code: "Code comptable pour tous les abonnements"
accounting_subscription_label: "Libellé abonnements"
general_subscription_label: "Libellé du compte pour tous les abonnements"
accounting_machine_code: "Code machines"
accounting_Machine_code: "Code machines"
general_machine_code: "Code comptable pour toutes les machines"
accounting_Machine_label: "Libellé machine"
general_machine_label: "Libellé du compte pour toutes les machines"
@ -467,11 +471,7 @@ fr:
general_space_code: "Code comptable pour tous les espaces"
accounting_Space_label: "Libellé espaces"
general_space_label: "Libellé du compte pour tous les espaces"
accounting_coupon_code: "Code pour codes promo"
general_coupon_code: "Code comptable pour tous les codes promo"
accounting_coupon_label: "Libellé codes promo"
general_coupon_label: "Libellé du compte pour tous les codes promo"
customization_of_SETTING_successfully_saved: "La personnalisation de {{SETTING}} a bien été enregistrée." # angular interpolation
codes_customization_success: "La personnalisation des codes comptables a bien été enregistrée."
export_accounting_data: "Exporter les données comptables"
export_to: "Exporter vers le logiciel comptable"
export_is_running: "L'export est en cours. Vous serez notifié lorsqu'il sera prêt."

View File

@ -435,10 +435,14 @@ pt:
accounting_codes: "Accounting codes" # translation_missing
accounting_journal_code: "Journal code" # translation_missing
general_journal_code: "Journal code" # translation_missing
accounting_client_code: "Customers code" # translation_missing
general_client_code: "Accounting code for all customers" # translation_missing
accounting_client_label: "Customers label" # translation_missing
general_client_label: "Account label for all customers" # translation_missing
accounting_card_client_code: "Card clients code" # translation_missing
card_client_code: "Accounting code for clients who paid by card" # translation_missing
accounting_card_client_label: "Card clients label" # translation_missing
card_client_label: "Account label for clients who paid by card" # translation_missing
accounting_site_client_code: "On site client code" # translation_missing
site_client_code: "Accounting code for clients who paid on site" # translation_missing
accounting_site_client_label: "On site client label" # translation_missing
site_client_label: "Accounting label for clients who paid on site" # translation_missing
accounting_wallet_code: "Wallet code" # translation_missing
general_wallet_code: "Accounting code for wallet credit" # translation_missing
accounting_wallet_label: "Wallet label" # translation_missing
@ -467,11 +471,7 @@ pt:
general_space_code: "Accounting code for all spaces" # translation_missing
accounting_Space_label: "Spaces label" # translation_missing
general_space_label: "Account label for all spaces" # translation_missing
accounting_coupon_code: "Coupons code" # translation_missing
general_coupon_code: "Accounting code for all coupons" # translation_missing
accounting_coupon_label: "Coupons label" # translation_missing
general_coupon_label: "Account label for all coupons" # translation_missing
customization_of_SETTING_successfully_saved: "Customization of the {{SETTING}} successfully saved." # angular interpolation # translation_missing
codes_customization_success: "Customization of accounting codes successfully saved." # angular interpolation # translation_missing
export_accounting_data: "Export accounting data" # translation_missing
export_to: "Export to the accounting software" # translation_missing
export_is_running: "A Exportação está em andamento. Você será notificado quando terminar."

View File

@ -43,7 +43,9 @@ Rails.application.routes.draw do
resources :themes
resources :licences
resources :admins, only: %i[index create destroy]
resources :settings, only: %i[show update index], param: :name
resources :settings, only: %i[show update index], param: :name do
patch '/bulk_update', action: 'bulk_update', on: :collection
end
resources :users, only: %i[index create]
resources :members, only: %i[index show create update destroy] do
get '/export_subscriptions', action: 'export_subscriptions', on: :collection