mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-18 07:52:23 +01:00
connect the export modal to the api
This commit is contained in:
parent
22d84e86f5
commit
a7f68b59dd
@ -905,7 +905,7 @@ Application.Controllers.controller('ClosePeriodModalController', ['$scope', '$ui
|
||||
}
|
||||
]);
|
||||
|
||||
Application.Controllers.controller('AccountingExportModalController', ['$scope', '$uibModalInstance', function ($scope, $uibModalInstance) {
|
||||
Application.Controllers.controller('AccountingExportModalController', ['$scope', '$uibModalInstance', 'Invoice', 'AccountingExport', function ($scope, $uibModalInstance, Invoice, AccountingExport) {
|
||||
|
||||
const SETTINGS = {
|
||||
acd: {
|
||||
@ -917,6 +917,8 @@ Application.Controllers.controller('AccountingExportModalController', ['$scope',
|
||||
}
|
||||
};
|
||||
|
||||
/* PUBLIC SCOPE */
|
||||
|
||||
// binding to radio button "export to"
|
||||
$scope.exportTarget = {
|
||||
software: null,
|
||||
@ -937,11 +939,16 @@ Application.Controllers.controller('AccountingExportModalController', ['$scope',
|
||||
}
|
||||
};
|
||||
|
||||
// Date of the first invoice
|
||||
$scope.firstInvoice = null;
|
||||
|
||||
/**
|
||||
* Validate the close period creation
|
||||
*/
|
||||
$scope.ok = function () {
|
||||
console.log('ok');
|
||||
AccountingExport.export($scope.exportTarget, function(res) {
|
||||
$uibModalInstance.close(res);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
@ -965,4 +972,19 @@ Application.Controllers.controller('AccountingExportModalController', ['$scope',
|
||||
* Just dismiss the modal window
|
||||
*/
|
||||
$scope.cancel = function () { $uibModalInstance.dismiss('cancel'); };
|
||||
|
||||
/* PRIVATE SCOPE */
|
||||
|
||||
/**
|
||||
* Kind of constructor: these actions will be realized first when the controller is loaded
|
||||
*/
|
||||
const initialize = function () {
|
||||
// if the invoice was payed with stripe, allow to refund through stripe
|
||||
Invoice.first(function (data) {
|
||||
$scope.firstInvoice = data.date;
|
||||
});
|
||||
};
|
||||
|
||||
// !!! MUST BE CALLED AT THE END of the controller
|
||||
return initialize();
|
||||
}]);
|
||||
|
12
app/assets/javascripts/services/accounting_export.js
Normal file
12
app/assets/javascripts/services/accounting_export.js
Normal file
@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
Application.Services.factory('AccountingExport', ['$resource', function ($resource) {
|
||||
return $resource('/api/accounting',
|
||||
{}, {
|
||||
export: {
|
||||
method: 'POST',
|
||||
url: '/api/accounting/export'
|
||||
}
|
||||
}
|
||||
);
|
||||
}]);
|
@ -10,6 +10,10 @@ Application.Services.factory('Invoice', ['$resource', function ($resource) {
|
||||
url: '/api/invoices/list',
|
||||
method: 'POST',
|
||||
isArray: true
|
||||
},
|
||||
first: {
|
||||
url: '/api/invoices/first',
|
||||
method: 'GET'
|
||||
}
|
||||
}
|
||||
);
|
||||
|
@ -65,6 +65,10 @@
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.modal-xl {
|
||||
width: 900px;
|
||||
}
|
||||
|
||||
// component card
|
||||
.card {
|
||||
position: relative;
|
||||
|
@ -285,10 +285,6 @@ input.form-control.as-writable {
|
||||
}
|
||||
}
|
||||
|
||||
.modal-xl {
|
||||
width: 900px;
|
||||
}
|
||||
|
||||
table.export-table-template {
|
||||
margin-top: 10px;
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
uib-datepicker-popup="{{datePicker.format}}"
|
||||
datepicker-options="datePicker.options"
|
||||
is-open="datePicker.opened.start"
|
||||
min-date="lastClosingEnd"
|
||||
min-date="firstInvoice"
|
||||
placeholder="{{datePicker.format}}"
|
||||
ng-click="toggleDatePicker($event, 'start')"
|
||||
required/>
|
||||
@ -34,7 +34,7 @@
|
||||
uib-datepicker-popup="{{datePicker.format}}"
|
||||
datepicker-options="datePicker.options"
|
||||
is-open="datePicker.opened.end"
|
||||
min-date="lastClosingEnd"
|
||||
min-date="exportTarget.startDate || firstInvoice"
|
||||
placeholder="{{datePicker.format}}"
|
||||
ng-click="toggleDatePicker($event, 'end')"
|
||||
required/>
|
||||
|
@ -6,7 +6,7 @@ class API::AccountingExportsController < API::ApiController
|
||||
before_action :authenticate_user!
|
||||
|
||||
def export
|
||||
authorize :export
|
||||
authorize :accounting_export
|
||||
|
||||
export = Export.where(category: 'accounting', export_type: 'accounting-software')
|
||||
.where('created_at > ?', Invoice.maximum('updated_at'))
|
||||
|
@ -51,6 +51,12 @@ class API::InvoicesController < API::ApiController
|
||||
end
|
||||
end
|
||||
|
||||
def first
|
||||
authorize Invoice
|
||||
invoice = Invoice.order(:created_at).first
|
||||
@first = invoice&.created_at
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def avoir_params
|
||||
|
@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Check the access policies for API::AccountingExportsController
|
||||
class AccountingExportsPolicy < ApplicationPolicy
|
||||
class AccountingExportPolicy < ApplicationPolicy
|
||||
def export?
|
||||
user.admin?
|
||||
end
|
@ -14,4 +14,8 @@ class InvoicePolicy < ApplicationPolicy
|
||||
def list?
|
||||
user.admin?
|
||||
end
|
||||
|
||||
def first?
|
||||
user.admin?
|
||||
end
|
||||
end
|
||||
|
1
app/views/api/invoices/first.json.jbuilder
Normal file
1
app/views/api/invoices/first.json.jbuilder
Normal file
@ -0,0 +1 @@
|
||||
json.date @first
|
@ -473,6 +473,27 @@ en:
|
||||
general_coupon_label: "Account label for all coupons"
|
||||
customization_of_SETTING_successfully_saved: "Customization of the {{SETTING}} successfully saved." # angular interpolation
|
||||
export_accounting_data: "Export accounting data"
|
||||
export_to: "Export to the accounting software"
|
||||
acd: "ACD"
|
||||
export_form_date: "Export from"
|
||||
export_to_date: "Export until"
|
||||
format: "File format"
|
||||
encoding: "Encoding"
|
||||
separator: "Separator"
|
||||
dateFormat: "Date format"
|
||||
columns: "Columns"
|
||||
exportColumns:
|
||||
journal_code: "Journal code"
|
||||
date: "Entry date"
|
||||
account_code: "Account code"
|
||||
account_label: "Account label"
|
||||
piece: "Document"
|
||||
line_label: "Entry label"
|
||||
debit_origin: "Origin debit"
|
||||
credit_origin: "Origin credit"
|
||||
debit_euro: "Euro debit"
|
||||
credit_euro: "Euro credit"
|
||||
lettering: "Lettering"
|
||||
|
||||
members:
|
||||
# management of users, labels, groups, and so on
|
||||
|
@ -473,6 +473,27 @@ es:
|
||||
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
|
||||
export_accounting_data: "Export accounting data" # translation_missing
|
||||
export_to: "Export to the accounting software" # translation_missing
|
||||
acd: "ACD" # translation_missing
|
||||
export_form_date: "Export from" # translation_missing
|
||||
export_to_date: "Export until" # translation_missing
|
||||
format: "File format" # translation_missing
|
||||
encoding: "Encoding" # translation_missing
|
||||
separator: "Separator" # translation_missing
|
||||
dateFormat: "Date format" # translation_missing
|
||||
columns: "Columns" # translation_missing
|
||||
exportColumns: # translation_missing
|
||||
journal_code: "Journal code" # translation_missing
|
||||
date: "Entry date" # translation_missing
|
||||
account_code: "Account code" # translation_missing
|
||||
account_label: "Account label" # translation_missing
|
||||
piece: "Document" # translation_missing
|
||||
line_label: "Entry label" # translation_missing
|
||||
debit_origin: "Origin debit" # translation_missing
|
||||
credit_origin: "Origin credit" # translation_missing
|
||||
debit_euro: "Euro debit" # translation_missing
|
||||
credit_euro: "Euro credit" # translation_missing
|
||||
lettering: "Lettering" # translation_missing
|
||||
|
||||
members:
|
||||
# management of users, labels, groups, and so on
|
||||
|
@ -473,6 +473,27 @@ fr:
|
||||
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
|
||||
export_accounting_data: "Exporter les données comptables"
|
||||
export_to: "Exporter vers le logiciel comptable"
|
||||
acd: "ACD"
|
||||
export_form_date: "Exporter depuis le"
|
||||
export_to_date: "Exporter jusqu'au"
|
||||
format: "Format de fichier"
|
||||
encoding: "Encodage"
|
||||
separator: "Séparateur"
|
||||
dateFormat: "Format de date"
|
||||
columns: "Colonnes"
|
||||
exportColumns:
|
||||
journal_code: "Code journal"
|
||||
date: "Date écriture"
|
||||
account_code: "Code compte"
|
||||
account_label: "Intitulé compte"
|
||||
piece: "Pièce"
|
||||
line_label: "Libellé écriture"
|
||||
debit_origin: "Débit origine"
|
||||
credit_origin: "Crédit origine"
|
||||
debit_euro: "Débit euro"
|
||||
credit_euro: "Crédit euro"
|
||||
lettering: "Lettrage"
|
||||
|
||||
members:
|
||||
# gestion des utilisateurs, des groupes, des étiquettes, etc.
|
||||
|
@ -473,6 +473,27 @@ pt:
|
||||
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
|
||||
export_accounting_data: "Export accounting data" # translation_missing
|
||||
export_to: "Export to the accounting software" # translation_missing
|
||||
acd: "ACD" # translation_missing
|
||||
export_form_date: "Export from" # translation_missing
|
||||
export_to_date: "Export until" # translation_missing
|
||||
format: "File format" # translation_missing
|
||||
encoding: "Encoding" # translation_missing
|
||||
separator: "Separator" # translation_missing
|
||||
dateFormat: "Date format" # translation_missing
|
||||
columns: "Columns" # translation_missing
|
||||
exportColumns: # translation_missing
|
||||
journal_code: "Journal code" # translation_missing
|
||||
date: "Entry date" # translation_missing
|
||||
account_code: "Account code" # translation_missing
|
||||
account_label: "Account label" # translation_missing
|
||||
piece: "Document" # translation_missing
|
||||
line_label: "Entry label" # translation_missing
|
||||
debit_origin: "Origin debit" # translation_missing
|
||||
credit_origin: "Origin credit" # translation_missing
|
||||
debit_euro: "Euro debit" # translation_missing
|
||||
credit_euro: "Euro credit" # translation_missing
|
||||
lettering: "Lettering" # translation_missing
|
||||
|
||||
members:
|
||||
# management of users, labels, groups, and so on
|
||||
|
@ -106,6 +106,7 @@ Rails.application.routes.draw do
|
||||
resources :invoices, only: %i[index show create] do
|
||||
get 'download', action: 'download', on: :member
|
||||
post 'list', action: 'list', on: :collection
|
||||
get 'first', action: 'first', on: :collection
|
||||
end
|
||||
|
||||
# for admin
|
||||
|
Loading…
x
Reference in New Issue
Block a user