diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index b6275d03c..05c1bbaa7 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -3884,3 +3884,18 @@ INSERT INTO `vn`.`calendarHolidays` (calendarHolidaysTypeFk, dated, calendarHoli (1, '2001-05-17', 1, 5), (1, '2001-05-18', 1, 5); +INSERT INTO vn.accountDetail +(id, value, accountDetailTypeFk, supplierAccountFk) +VALUES + (21, 'ES12345B12345678', 3, 241), + (35, 'ES12346B12345679', 3, 241); + +INSERT INTO vn.accountDetailType +(id, description) +VALUES + (1, 'IBAN'), + (2, 'SWIFT'), + (3, 'Referencia Remesas'), + (4, 'Referencia Transferencias'), + (5, 'Referencia Nominas'), + (6, 'ABA'); diff --git a/print/templates/reports/sepa-core/sepa-core.html b/print/templates/reports/sepa-core/sepa-core.html index 363ebdfe5..e5d14d06c 100644 --- a/print/templates/reports/sepa-core/sepa-core.html +++ b/print/templates/reports/sepa-core/sepa-core.html @@ -27,8 +27,7 @@ {{$t('supplier.identifier')}} -
{{supplier.iban}}
-
{{supplier.nif}}
+
{{supplier.accountDetailValue.join(', ')}}
diff --git a/print/templates/reports/sepa-core/sepa-core.js b/print/templates/reports/sepa-core/sepa-core.js index f32fd92e7..6b941556e 100755 --- a/print/templates/reports/sepa-core/sepa-core.js +++ b/print/templates/reports/sepa-core/sepa-core.js @@ -7,7 +7,11 @@ module.exports = { async serverPrefetch() { this.client = await this.findOneFromDef('client', [this.companyId, this.companyId, this.id]); this.checkMainEntity(this.client); - this.supplier = await this.findOneFromDef('supplier', [this.companyId, this.companyId, this.id]); + const suppliers = await this.rawSqlFromDef('supplier', [this.companyId, this.companyId, this.id]); + this.supplier = { + ...suppliers[0], + accountDetailValue: suppliers.map(val => val?.accountDetailValue) + }; }, props: { id: { @@ -23,12 +27,11 @@ module.exports = { methods: { getSupplierCif() { return db.findOne(` - SELECT sa.iban, s.nif + SELECT DISTINCT ad.value FROM supplierAccount sa - JOIN company co ON co.supplierAccountFk = sa.id - JOIN supplier s ON sa.supplierFk = s.id - WHERE co.id = ? - AND ad.accountDetailTypeFk = 3`) [this.companyId]; + JOIN accountDetail ad ON ad.supplierAccountFk = sa.id + JOIN accountDetailType adt ON adt.id = ad.accountDetailTypeFk AND adt.id = 3 + WHERE sa.supplierFk = ?`) [this.companyId]; } } diff --git a/print/templates/reports/sepa-core/sql/supplier.sql b/print/templates/reports/sepa-core/sql/supplier.sql index 156fc71c0..a49896244 100644 --- a/print/templates/reports/sepa-core/sql/supplier.sql +++ b/print/templates/reports/sepa-core/sql/supplier.sql @@ -1,15 +1,16 @@ SELECT - m.code mandateCode, + m.code AS mandateCode, s.name, s.street, - sc.name country, + sc.name AS country, s.postCode, s.city, - sp.name province, + sp.name AS province, s.nif, sa.iban, sa.supplierFk, - be.name bankName + be.name AS bankName, + ad.value AS accountDetailValue FROM client c LEFT JOIN mandate m ON m.clientFk = c.id AND m.companyFk = ? AND m.finished IS NULL @@ -19,9 +20,10 @@ FROM LEFT JOIN province p ON p.id = c.provinceFk LEFT JOIN supplierAccount sa ON sa.supplierFk = s.id LEFT JOIN bankEntity be ON sa.bankEntityFk = be.id + LEFT JOIN accountDetail ad ON ad.supplierAccountFk = sa.id + LEFT JOIN accountDetailType adt ON adt.id = ad.accountDetailTypeFk AND adt.id = 3 WHERE (m.companyFk = ? OR m.companyFk IS NULL) AND (c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk)) ORDER BY - m.created DESC -LIMIT 1; + m.created DESC;