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

(feat) VAT for store's product and Accounting code/label

This commit is contained in:
Du Peng 2022-09-08 20:37:22 +02:00
parent cd1bfe976c
commit 50276f5b41
10 changed files with 74 additions and 8 deletions

View File

@ -98,6 +98,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
rateTraining: '',
rateEvent: '',
rateSubscription: '',
rateProduct: '',
editTemplateUrl: '/admin/invoices/settings/editMultiVAT.html',
historyTemplateUrl: '/admin/invoices/settings/multiVATHistory.html'
},
@ -203,6 +204,14 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
name: 'accounting_Pack_label',
value: settings.accounting_Pack_label
},
productCode: {
name: 'accounting_Product_code',
value: settings.accounting_Product_code
},
productLabel: {
name: 'accounting_Product_label',
value: settings.accounting_Product_label
},
errorCode: {
name: 'accounting_Error_code',
value: settings.accounting_Error_code
@ -550,7 +559,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
}]
});
return editMultiVATModalInstance.result.then(function (result) {
['Machine', 'Space', 'Training', 'Event', 'Subscription'].forEach(rateType => {
['Machine', 'Space', 'Training', 'Event', 'Subscription', 'Product'].forEach(rateType => {
const value = _.isFinite(result.multiVAT[`rate${rateType}`]) ? result.multiVAT[`rate${rateType}`] + '' : '';
Setting.update({ name: `invoice_VAT-rate_${rateType}` }, { value }, function (data) {
return growl.success(_t('app.admin.invoices.VAT_rate_successfully_saved'));
@ -1054,6 +1063,7 @@ Application.Controllers.controller('InvoicesController', ['$scope', '$state', 'I
$scope.invoice.multiVAT.rateTraining = settings['invoice_VAT-rate_Training'] ? parseFloat(settings['invoice_VAT-rate_Training']) : '';
$scope.invoice.multiVAT.rateEvent = settings['invoice_VAT-rate_Event'] ? parseFloat(settings['invoice_VAT-rate_Event']) : '';
$scope.invoice.multiVAT.rateSubscription = settings['invoice_VAT-rate_Subscription'] ? parseFloat(settings['invoice_VAT-rate_Subscription']) : '';
$scope.invoice.multiVAT.rateProduct = settings['invoice_VAT-rate_Product'] ? parseFloat(settings['invoice_VAT-rate_Product']) : '';
$scope.invoice.number.model = settings['invoice_order-nb'];
$scope.invoice.code.model = settings['invoice_code-value'];
$scope.invoice.code.active = (settings['invoice_code-active'] === 'true');

View File

@ -60,6 +60,7 @@ export const invoicesSettings = [
'invoice_VAT-rate_Space',
'invoice_VAT-rate_Event',
'invoice_VAT-rate_Subscription',
'invoice_VAT-rate_Product',
'invoice_text',
'invoice_legals',
'invoice_prefix',
@ -114,7 +115,9 @@ export const accountingSettings = [
'accounting_Event_code',
'accounting_Event_label',
'accounting_Space_code',
'accounting_Space_label'
'accounting_Space_label',
'accounting_Product_code',
'accounting_Product_label'
];
export const modulesSettings = [

View File

@ -948,13 +948,13 @@ angular.module('application.router', ['ui.router'])
settings: ['Setting', function (Setting) {
return Setting.query({
names: "['invoice_legals', 'invoice_text', 'invoice_VAT-rate', 'invoice_VAT-rate_Machine', 'invoice_VAT-rate_Training', 'invoice_VAT-rate_Space', " +
"'invoice_VAT-rate_Event', 'invoice_VAT-rate_Subscription', 'invoice_VAT-active', 'invoice_order-nb', 'invoice_code-value', " +
"'invoice_VAT-rate_Event', 'invoice_VAT-rate_Subscription', 'invoice_VAT-rate_Product', 'invoice_VAT-active', 'invoice_order-nb', 'invoice_code-value', " +
"'invoice_code-active', 'invoice_reference', 'invoice_logo', 'accounting_journal_code', 'accounting_card_client_code', " +
"'accounting_card_client_label', 'accounting_wallet_client_code', 'accounting_wallet_client_label', 'invoicing_module', " +
"'accounting_other_client_code', 'accounting_other_client_label', 'accounting_wallet_code', 'accounting_wallet_label', " +
"'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', " +
"'accounting_Event_code', 'accounting_Event_label', 'accounting_Space_code', 'accounting_Space_label', 'accounting_Product_code', 'accounting_Product_label', " +
"'payment_gateway', 'accounting_Error_code', 'accounting_Error_label', 'payment_schedule_prefix', " +
"'feature_tour_display', 'online_payment_module', 'stripe_public_key', 'stripe_currency', 'invoice_prefix', " +
"'accounting_Pack_code', 'accounting_Pack_label']"

View File

@ -116,6 +116,16 @@
<input type="text" id="packLabel" ng-model="settings.packLabel.value" class="form-control" placeholder="{{ 'app.admin.invoices.general_pack_label' | translate }}"/>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label for="productCode" translate>{{ 'app.admin.invoices.accounting_Product_code' }}</label>
<input type="text" id="productCode" ng-model="settings.productCode.value" class="form-control" placeholder="{{ 'app.admin.invoices.general_product_code' | translate }}" />
</div>
<div class="col-md-6">
<label for="productLabel" translate>{{ 'app.admin.invoices.accounting_Product_label' }}</label>
<input type="text" id="productLabel" ng-model="settings.productLabel.value" class="form-control" placeholder="{{ 'app.admin.invoices.general_product_label' | translate }}"/>
</div>
</div>
<div class="row">
<div class="col-md-6">
<label for="spaceCode" translate>{{ 'app.admin.invoices.accounting_Error_code' }}</label>

View File

@ -49,6 +49,14 @@
<button class="btn pull-right" ng-click="showMultiRateHistory('Subscription')"><i class="fa fa-history"></i></button>
</div>
</div>
<div class="form-group">
<label for="vatRateProduct" class="control-label" translate>{{ 'app.admin.invoices.VAT_rate_product' }}</label>
<div class="input-group">
<span class="input-group-addon">% </span>
<input id="vatRateSubscription" type="number" ng-model="multiVAT.rateProduct" class="form-control multi-vat-rate-input" min="0" max="100"/>
<button class="btn pull-right" ng-click="showMultiRateHistory('Product')"><i class="fa fa-history"></i></button>
</div>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-warning" ng-click="ok()" translate>{{ 'app.shared.buttons.confirm' }}</button>

View File

@ -23,7 +23,7 @@ class InvoiceItem < Footprintable
# deduct VAT
vat_service = VatHistoryService.new
vat_rate = vat_service.invoice_item_vat(self)
Rational(amount_after_coupon / (vat_rate / 100.00 + 1)).round.to_f
Rational(amount_after_coupon / ((vat_rate / 100.00) + 1)).round.to_f
end
# return the VAT amount for this item
@ -31,7 +31,7 @@ class InvoiceItem < Footprintable
amount_after_coupon - net_amount
end
# return invoice item type (Machine/Training/Space/Event/Subscription) used to determine the VAT rate
# return invoice item type (Machine/Training/Space/Event/Subscription/Order) used to determine the VAT rate
def invoice_item_type
if object_type == Reservation.name
object.try(:reservable_type) || ''
@ -39,6 +39,8 @@ class InvoiceItem < Footprintable
Subscription.name
elsif object_type == StatisticProfilePrepaidPack.name
object.prepaid_pack.priceable_type
elsif object_type == Order.name
Product.name
else
''
end

View File

@ -33,6 +33,7 @@ class Setting < ApplicationRecord
invoice_VAT-rate_Space
invoice_VAT-rate_Event
invoice_VAT-rate_Subscription
invoice_VAT-rate_Product
invoice_text
invoice_legals
booking_window_start
@ -74,6 +75,8 @@ class Setting < ApplicationRecord
accounting_Event_label
accounting_Space_code
accounting_Space_label
accounting_Product_code
accounting_Product_label
hub_last_version
hub_public_key
fab_analytics

View File

@ -72,6 +72,8 @@ class AccountingExportService
rows << "#{wallet_row(invoice)}\n"
when 'StatisticProfilePrepaidPack'
rows << "#{pack_row(invoice)}\n"
when 'Order'
rows << "#{product_row(invoice)}\n"
when 'Error'
items = invoice.invoice_items.reject { |ii| ii.object_type == 'Subscription' }
items.each do |item|
@ -148,6 +150,16 @@ class AccountingExportService
)
end
def product_row(invoice)
row(
invoice,
account(invoice, :product),
account(invoice, :product, type: :label),
invoice.invoice_items.first.net_amount / 100.00,
line_label: label(invoice)
)
end
# Generate the "VAT" row, which contains the credit to the VAT account, with VAT amount only
def vat_row(invoice)
total = invoice.invoice_items.map(&:net_amount).sum
@ -235,6 +247,12 @@ class AccountingExportService
else
Rails.logger.debug { "WARN: Invoice #{invoice.id} has no prepaid-pack" }
end
when :product
if invoice.main_item.object_type == 'Order'
Setting.get("accounting_VAT_#{type}")
else
Rails.logger.debug { "WARN: Invoice #{invoice.id} has no prepaid-pack" }
end
when :error
Setting.get("accounting_Error_#{type}")
else
@ -275,7 +293,9 @@ class AccountingExportService
reference = invoice.reference
items = invoice.subscription_invoice? ? [I18n.t('accounting_export.subscription')] : []
items.push I18n.t("accounting_export.#{invoice.main_item.object.reservable_type}_reservation") if invoice.main_item.object_type == 'Reservation'
if invoice.main_item.object_type == 'Reservation'
items.push I18n.t("accounting_export.#{invoice.main_item.object.reservable_type}_reservation")
end
items.push I18n.t('accounting_export.wallet') if invoice.main_item.object_type == 'WalletTransaction'
summary = items.join(' + ')

View File

@ -599,6 +599,7 @@ en:
VAT_rate_training: "Training reservation"
VAT_rate_event: "Event reservation"
VAT_rate_subscription: "Subscription"
VAT_rate_product: "Products (store)"
changed_at: "Changed at"
changed_by: "By"
deleted_user: "Deleted user"
@ -714,6 +715,10 @@ en:
general_pack_code: "Accounting code for prepaid-packs"
accounting_Pack_label: "Prepaid-pack label"
general_pack_label: "Account label for prepaid-packs"
accounting_Product_code: "Product code (Store)"
general_product_code: "Accounting code for products (Store)"
accounting_Product_label: "Product label (Store)"
general_product_label: "Account label for products (Store)"
accounting_Error_code: "Errors code"
general_error_code: "Accounting code for erroneous invoices"
accounting_Error_label: "Errors label"
@ -2054,4 +2059,4 @@ en:
title: 'Settings'
withdrawal_instructions: 'Product withdrawal instructions'
withdrawal_info: "This text is displayed on the checkout page to inform the client about the products withdrawal method"
save: "Save"
save: "Save"

View File

@ -599,6 +599,7 @@ fr:
VAT_rate_training: "Réservation de formations"
VAT_rate_event: "Réservation d'événements"
VAT_rate_subscription: "Abonnements"
VAT_rate_product: "Achat de produits (boutique)"
changed_at: "Changé le"
changed_by: "Par"
deleted_user: "Utilisateur supprimé"
@ -714,6 +715,10 @@ fr:
general_pack_code: "Code comptable pour tous les packs prépayés"
accounting_Pack_label: "Libellé pack prépayé"
general_pack_label: "Libellé du compte pour tous les packs prépayés"
accounting_Product_code: "Code produit (Boutique)"
general_product_code: "Code comptable pour tous les produits (Boutique)"
accounting_Product_label: "Libellé produit (Boutique)"
general_product_label: "Libellé du compte pour tous les produits (Boutique)"
accounting_Error_code: "Code erreurs"
general_error_code: "Code comptable pour les factures en erreur"
accounting_Error_label: "Libellé erreurs"