diff --git a/back/models/payment.json b/back/models/payment.json index ed354969e..2bc665503 100644 --- a/back/models/payment.json +++ b/back/models/payment.json @@ -52,7 +52,7 @@ }, "payMethod": { "type": "belongsTo", - "model": "PayMethodFk", + "model": "PayMethod", "foreignKey": "payMethodFk" }, "company": { @@ -61,4 +61,4 @@ "foreignKey": "companyFk" } } -} \ No newline at end of file +} diff --git a/db/dump/fixtures.before.sql b/db/dump/fixtures.before.sql index 76ccc7c1e..b7197d1db 100644 --- a/db/dump/fixtures.before.sql +++ b/db/dump/fixtures.before.sql @@ -2641,9 +2641,9 @@ REPLACE INTO `vn`.`invoiceIn`(`id`, `serialNumber`,`serial`, `supplierFk`, `issu (9, 1009, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1242, 0, 442, 1,util.VN_CURDATE()), (10, 1010, 'R', 2, DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), DATE_ADD(util.VN_CURDATE(), INTERVAL -1 MONTH), 1243, 0, 442, 1,util.VN_CURDATE()); -INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageFarmerWithholdingFk`, `daysAgo`) +INSERT INTO `vn`.`invoiceInConfig` (`id`, `retentionRate`, `retentionName`, `sageFarmerWithholdingFk`, `daysAgo`, `balanceStartingDate`) VALUES - (1, -2, '2% retention', 2, 45); + (1, -2, '2% retention', 2, 45, '2000-01-01'); INSERT INTO `vn`.`invoiceInDueDay`(`invoiceInFk`, `dueDated`, `bankFk`, `amount`) VALUES @@ -4052,6 +4052,9 @@ INSERT IGNORE INTO vn.saySimpleConfig (url, defaultChannel) INSERT INTO vn.workerIrpf (workerFk,spouseNif, geographicMobilityDate) VALUES (1106,'26493101E','2019-09-20'); +INSERT INTO vn.payment (received, supplierFk, amount, currencyFk, divisa, bankFk, payMethodFk, bankingFees, concept, companyFk, created, isConciliated, dueDated, workerFk) VALUES + (util.VN_CURDATE(), 1, 1000.00, 1, NULL, 1, 1, 0.0, 'n/pago', 442, util.VN_CURDATE(), 1, util.VN_CURDATE(), 9); + INSERT INTO vn.referenceRate (currencyFk, dated, value) VALUES (2, '2000-12-01', 1.0495), (2, '2001-01-01', 1.0531), diff --git a/db/routines/vn/procedures/entry_transfer.sql b/db/routines/vn/procedures/entry_transfer.sql index 5b83ae532..c02365092 100644 --- a/db/routines/vn/procedures/entry_transfer.sql +++ b/db/routines/vn/procedures/entry_transfer.sql @@ -1,5 +1,5 @@ DELIMITER $$ -CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`entry_transfer`( +CREATE OR REPLACE DEFINER=`vn`@`localhost` PROCEDURE `vn`.`entry_transfer`( vOriginalEntry INT, OUT vNewEntryFk INT ) diff --git a/db/routines/vn/procedures/supplier_statementWithEntries.sql b/db/routines/vn/procedures/supplier_statementWithEntries.sql index c0014f8e5..ad80e2c9f 100644 --- a/db/routines/vn/procedures/supplier_statementWithEntries.sql +++ b/db/routines/vn/procedures/supplier_statementWithEntries.sql @@ -41,6 +41,7 @@ BEGIN ) currencyBalance FROM ( SELECT NULL bankFk, + NULL bank, ii.companyFk, ii.serial, ii.id, @@ -74,6 +75,7 @@ BEGIN GROUP BY iid.id, ii.id UNION ALL SELECT p.bankFk, + a.bank, p.companyFk, NULL, p.id, @@ -109,6 +111,7 @@ BEGIN AND (vIsConciliated = p.isConciliated OR NOT vIsConciliated) UNION ALL SELECT NULL, + NULL bankFk, companyFk, NULL, se.id, @@ -136,6 +139,7 @@ BEGIN AND (vIsConciliated = se.isConciliated OR NOT vIsConciliated) UNION ALL SELECT NULL bankFk, + NULL, e.companyFk, 'E' serial, e.invoiceNumber id, @@ -154,7 +158,7 @@ BEGIN JOIN travel tr ON tr.id = e.travelFk JOIN currency c ON c.id = e.currencyFk WHERE e.supplierFk = vSupplierFk - AND tr.landed >= CURDATE() + AND tr.landed >= util.VN_CURDATE() AND e.invoiceInFk IS NULL AND vHasEntries ORDER BY (dated IS NULL AND NOT isBooked), diff --git a/db/versions/11425-aquaCordyline/00-firstScript.sql b/db/versions/11425-aquaCordyline/00-firstScript.sql new file mode 100644 index 000000000..f8b194e8a --- /dev/null +++ b/db/versions/11425-aquaCordyline/00-firstScript.sql @@ -0,0 +1,2 @@ +INSERT IGNORE INTO salix.ACL (model, property, accessType, permission, principalType, principalId) +VALUES('Entry', 'transfer', 'WRITE', 'ALLOW', 'ROLE', 'coolerBoss'); diff --git a/modules/entry/back/methods/entry/transfer.js b/modules/entry/back/methods/entry/transfer.js index db6873663..fc1c4808a 100644 --- a/modules/entry/back/methods/entry/transfer.js +++ b/modules/entry/back/methods/entry/transfer.js @@ -1,6 +1,7 @@ module.exports = Self => { Self.remoteMethodCtx('transfer', { description: 'Transfer merchandise from one entry to the next day', + accessType: 'WRITE', accepts: [ { arg: 'id', diff --git a/modules/supplier/back/methods/supplier/receipts.js b/modules/supplier/back/methods/supplier/receipts.js new file mode 100644 index 000000000..cc7b03a42 --- /dev/null +++ b/modules/supplier/back/methods/supplier/receipts.js @@ -0,0 +1,100 @@ + +const ParameterizedSQL = require('loopback-connector').ParameterizedSQL; +const {buildFilter, mergeFilters} = require('vn-loopback/util/filter'); +module.exports = Self => { + Self.remoteMethodCtx('receipts', { + description: 'Find all suppliers matched by the filter', + accessType: 'READ', + accepts: [ + { + arg: 'filter', + type: 'object', + description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', + http: {source: 'query'} + }, { + arg: 'supplierId', + type: 'number', + description: 'The supplier id', + }, + { + arg: 'companyId', + type: 'number', + description: 'The company id', + }, + { + arg: 'currencyFk', + type: 'number', + description: 'The currency', + default: 1, + }, + { + arg: 'bankFk', + type: 'number', + description: 'The bank', + default: 1, + }, + { + arg: 'orderBy', + type: 'string', + description: 'The supplier fiscal id', + enum: ['issued', ' bookEntried', ' booked', ' dueDate'], + }, + { + arg: 'isConciliated', + default: false, + type: 'boolean', + }, + ], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/receipts`, + verb: 'GET' + } + }); + + Self.receipts = async(ctx, filter, options) => { + const conn = Self.dataSource.connector; + const myOptions = {userId: ctx.req.accessToken.userId}; + const args = ctx.args; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const where = buildFilter(ctx.args, (param, value) => { + switch (param) { + case 'bankFk': + return {[param]: value}; + } + }); + + let stmts = []; + + stmts.push(new ParameterizedSQL('CALL vn.supplier_statementWithEntries(?,?,?,?,?,?)', [ + args.supplierId, + args.currencyFk, + args.companyId, + args.orderBy ?? 'issued', + args.isConciliated ?? false, + false + ])); + + const stmt = new ParameterizedSQL(` + SELECT * + FROM tmp.supplierStatement`); + + filter = mergeFilters(args.filter, {where}); + + stmt.merge(conn.makeSuffix(filter)); + stmts.push(stmt); + stmts.push(`DROP TEMPORARY TABLE tmp.supplierStatement`); + + const sql = ParameterizedSQL.join(stmts, ';'); + const results = await conn.executeStmt(sql); + const resultsIndex = stmts.length - 2; + const result = results[resultsIndex]; + return result; + }; +}; diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index 7e6908d57..63bd65fbd 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -8,6 +8,7 @@ module.exports = Self => { require('../methods/supplier/updateFiscalData')(Self); require('../methods/supplier/consumption')(Self); require('../methods/supplier/freeAgencies')(Self); + require('../methods/supplier/receipts')(Self); require('../methods/supplier/campaignMetricsPdf')(Self); require('../methods/supplier/campaignMetricsEmail')(Self); require('../methods/supplier/newSupplier')(Self); diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 97e6a283c..4895a6107 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -1,5 +1,4 @@ module.exports = Self => { - const validateTin = require('vn-loopback/util/validateTin'); require('../methods/worker/filter')(Self); require('../methods/worker/mySubordinates')(Self); require('../methods/worker/isSubordinate')(Self); @@ -23,26 +22,10 @@ module.exports = Self => { require('../methods/worker/getAvailablePda')(Self); require('../methods/worker/myTeam')(Self); - Self.validateAsync('fi', tinIsValid, { - message: 'Invalid TIN' - }); - Self.canModifyAbsenceInPast = async(ctx, time) => { const hasPrivs = await Self.app.models.ACL.checkAccessAcl(ctx, 'Worker', 'canModifyAbsenceInPast', 'WRITE'); const today = Date.vnNew(); today.setHours(0, 0, 0, 0); return hasPrivs || today.getTime() < time; }; - - async function tinIsValid(err, done) { - const country = await Self.app.models.Country.findOne({ - fields: ['code'], - where: {id: this.originCountryFk} - }); - const code = country ? country.code.toLowerCase() : null; - - if (!this.fi || !validateTin(this.fi, code)) - err(); - done(); - } };