diff --git a/modules/invoiceIn/front/basic-data/index.html b/modules/invoiceIn/front/basic-data/index.html
index be89e502c..4b206372d 100644
--- a/modules/invoiceIn/front/basic-data/index.html
+++ b/modules/invoiceIn/front/basic-data/index.html
@@ -5,6 +5,24 @@
form="form"
save="patch">
+
+
+
+
+
+
\ No newline at end of file
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/modules/invoiceIn/front/basic-data/index.js b/modules/invoiceIn/front/basic-data/index.js
index 6a39f35cd..40a01ac18 100644
--- a/modules/invoiceIn/front/basic-data/index.js
+++ b/modules/invoiceIn/front/basic-data/index.js
@@ -1,9 +1,177 @@
import ngModule from '../module';
import Section from 'salix/components/section';
+import UserError from 'core/lib/user-error';
+
+class Controller extends Section {
+ constructor($element, $, vnFile) {
+ super($element, $, vnFile);
+ this.vnFile = vnFile;
+ this.getAllowedContentTypes();
+ this._fileExists = false;
+ }
+
+ get fileExists() {
+ return this._fileExists;
+ }
+
+ getAllowedContentTypes() {
+ this.$http.get('DmsContainers/allowedContentTypes').then(res => {
+ const contentTypes = res.data.join(', ');
+ this.allowedContentTypes = contentTypes;
+ });
+ }
+
+ async checkFileExists(dmsId) {
+ if (!dmsId) return;
+ let filter = {
+ fields: ['id']
+ };
+ await this.$http.get(`Dms/${dmsId}`, {filter})
+ .then(() => this._fileExists = false)
+ .catch(() => this._fileExists = true);
+ }
+
+ openEditDialog(dmsId) {
+ this.getFile(dmsId).then(() => this.$.dmsEditDialog.show());
+ }
+
+ openCreateDialog() {
+ this.dms = {
+ reference: null,
+ warehouseId: null,
+ companyId: null,
+ dmsTypeId: null,
+ description: null,
+ hasFile: true,
+ hasFileAttached: true,
+ files: null
+ };
+ this.$.dmsCreateDialog.show();
+ }
+
+ async getFile(dmsId) {
+ const path = `Dms/${dmsId}`;
+ await this.$http.get(path).then(res => {
+ const dms = res.data && res.data;
+ this.dms = {
+ dmsId: dms.id,
+ reference: dms.reference,
+ warehouseId: dms.warehouseFk,
+ companyId: dms.companyFk,
+ dmsTypeId: dms.dmsTypeFk,
+ description: dms.description,
+ hasFile: dms.hasFile,
+ hasFileAttached: false,
+ files: []
+ };
+ });
+ }
+
+ get contentTypesInfo() {
+ return this.$t('ContentTypesInfo', {
+ allowedContentTypes: this.allowedContentTypes
+ });
+ }
+
+ downloadFile(dmsId) {
+ this.vnFile.download(`api/dms/${dmsId}/downloadFile`);
+ }
+
+ onFileChange(files) {
+ let hasFileAttached = false;
+ if (files.length > 0)
+ hasFileAttached = true;
+
+ this.$.$applyAsync(() => {
+ this.dms.hasFileAttached = hasFileAttached;
+ });
+ }
+
+ onEdit() {
+ if (!this.dms.companyId)
+ throw new UserError(`The company can't be empty`);
+ if (!this.dms.warehouseId)
+ throw new UserError(`The warehouse can't be empty`);
+ if (!this.dms.dmsTypeId)
+ throw new UserError(`The DMS Type can't be empty`);
+ if (!this.dms.description)
+ throw new UserError(`The description can't be empty`);
+ if (!this.dms.files)
+ throw new UserError(`The files can't be empty`);
+
+ const query = `dms/${this.dms.dmsId}/updateFile`;
+ const options = {
+ method: 'POST',
+ url: query,
+ params: this.dms,
+ headers: {
+ 'Content-Type': undefined
+ },
+ transformRequest: files => {
+ const formData = new FormData();
+
+ for (let i = 0; i < files.length; i++)
+ formData.append(files[i].name, files[i]);
+
+ return formData;
+ },
+ data: this.dms.files
+ };
+
+ this.$http(options).then(res => {
+ if (res) {
+ this.vnApp.showSuccess(this.$t('Data saved!'));
+ this.$.watcher.updateOriginalData();
+ }
+ });
+ }
+
+ onCreate() {
+ if (!this.dms.companyId)
+ throw new UserError(`The company can't be empty`);
+ if (!this.dms.warehouseId)
+ throw new UserError(`The warehouse can't be empty`);
+ if (!this.dms.dmsTypeId)
+ throw new UserError(`The DMS Type can't be empty`);
+ if (!this.dms.description)
+ throw new UserError(`The description can't be empty`);
+ if (!this.dms.files)
+ throw new UserError(`The files can't be empty`);
+
+ const query = `Dms/uploadFile`;
+ const options = {
+ method: 'POST',
+ url: query,
+ params: this.dms,
+ headers: {
+ 'Content-Type': undefined
+ },
+ transformRequest: files => {
+ const formData = new FormData();
+
+ for (let i = 0; i < files.length; i++)
+ formData.append(files[i].name, files[i]);
+
+ return formData;
+ },
+ data: this.dms.files
+ };
+
+ this.$http(options).then(res => {
+ if (res) {
+ this.vnApp.showSuccess(this.$t('Data saved!'));
+ this.invoiceIn.dmsFk = res.data[0].id;
+ this.$.watcher.updateOriginalData();
+ }
+ });
+ }
+}
+
+Controller.$inject = ['$element', '$scope', 'vnFile'];
ngModule.vnComponent('vnInvoiceInBasicData', {
template: require('./index.html'),
- controller: Section,
+ controller: Controller,
bindings: {
invoiceIn: '<'
}
diff --git a/modules/invoiceIn/front/basic-data/locale/en.yml b/modules/invoiceIn/front/basic-data/locale/en.yml
new file mode 100644
index 000000000..19f4dc8c2
--- /dev/null
+++ b/modules/invoiceIn/front/basic-data/locale/en.yml
@@ -0,0 +1 @@
+ContentTypesInfo: Allowed file types {{allowedContentTypes}}
diff --git a/modules/invoiceIn/front/basic-data/locale/es.yml b/modules/invoiceIn/front/basic-data/locale/es.yml
new file mode 100644
index 000000000..e2e494fa5
--- /dev/null
+++ b/modules/invoiceIn/front/basic-data/locale/es.yml
@@ -0,0 +1,15 @@
+Upload file: Subir fichero
+Edit file: Editar fichero
+Upload: Subir
+Document: Documento
+ContentTypesInfo: "Tipos de archivo permitidos: {{allowedContentTypes}}"
+Generate identifier for original file: Generar identificador para archivo original
+File management: GestiĆ³n documental
+Hard copy: Copia
+This file will be deleted: Este fichero va a ser borrado
+Are you sure?: Estas seguro?
+File deleted: Fichero eliminado
+Remove file: Eliminar fichero
+Download file: Descargar fichero
+Edit document: Editar documento
+Create document: Crear documento