refs #5525 letter debtor st
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Satorres 2023-12-13 11:29:50 +01:00
parent 920b38c929
commit 556b403a5b
3 changed files with 36 additions and 22 deletions

View File

@ -1,10 +1,9 @@
ALTER TABLE `vn`.`company` MODIFY COLUMN `supplierAccountFk` mediumint(8) unsigned DEFAULT NULL NULL COMMENT 'Cuenta por defecto para ingresos desde este pais';
CREATE TABLE `vn`.`supplierAccountI18n` (
supplierAccountFk mediumint(8) unsigned NOT NULL,
countryFk mediumint(8) unsigned NOT NULL,
FOREIGN KEY (supplierAccountFk) REFERENCES supplierAccount(id),
FOREIGN KEY (countryFk) REFERENCES country(id)
);
ALTER TABLE `vn`.`supplierAccount`
ADD COLUMN `countryFk` mediumint(8) unsigned DEFAULT NULL,
ADD CONSTRAINT `fk_supplierAccount_country`
FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON UPDATE CASCADE;

View File

@ -7,12 +7,28 @@ module.exports = {
name: 'letter-debtor-st',
async serverPrefetch() {
this.debtor = await db.findOne(`
SELECT sa.iban, be.name bankName
FROM supplierAccount sa
JOIN bankEntity be ON sa.bankEntityFk = be.id
JOIN client c ON c.countryFk = sa.countryFk
WHERE c.id = ? OR (c.id IS NULL AND c.countryFk = sa.countryFk);`,
[this.id]);
SELECT sa.iban,
be.name bankName,
sa.countryFk,
c.countryFk
FROM supplierAccount sa
JOIN bankEntity be ON sa.bankEntityFk = be.id
LEFT JOIN company co ON co.supplierAccountFk = sa.id
LEFT JOIN client c ON c.countryFk = sa.countryFk
WHERE c.id = ?
ORDER BY co.id DESC
LIMIT 1;
`, [this.id]);
if (!this.debtor.length) {
this.debtor = await db.findOne(`
SELECT sa.iban,
be.name bankName
FROM supplierAccount sa
JOIN bankEntity be ON sa.bankEntityFk = be.id
JOIN company co ON co.supplierAccountFk = sa.id
WHERE co.code = ?;
`, [this.companyCode]);
}
},
data() {
return {

View File

@ -1,10 +1,9 @@
SELECT
c.dueDay,
c.iban,
sa.iban,
be.name AS bankName
FROM client c
JOIN company AS cny
JOIN supplierAccount AS sa ON sa.id = cny.supplierAccountFk
JOIN bankEntity be ON be.id = sa.bankEntityFk
WHERE c.id = ? AND cny.id = ?
SELECT c.dueDay,
sa.iban,
be.name bankName
FROM client c
JOIN supplierAccount sa ON sa.id = cny.supplierAccountFk
JOIN bankEntity be ON be.id = sa.bankEntityFk
JOIN company cny
WHERE c.id = ?
AND cny.id = ?