faltan test
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Javi Gallego 2021-09-28 10:57:51 +02:00
parent e5c9ea850b
commit 4f1fd5412d
6 changed files with 93 additions and 26 deletions

View File

@ -0,0 +1,2 @@
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES('InvoiceInDueDay', '*', '*', 'ALLOW', 'ROLE', 'administrative');

View File

@ -0,0 +1,52 @@
module.exports = Self => {
Self.remoteMethodCtx('getTotals', {
description: 'Return totals for an invoiceIn',
accessType: 'READ',
accepts: {
arg: 'id',
type: 'number',
required: true,
description: 'invoiceIn id',
http: {source: 'path'}
},
returns: {
type: 'object',
root: true
},
http: {
path: '/:id/getTotals',
verb: 'GET'
}
});
Self.getTotals = async(ctx, id, options) => {
let tx;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
return (await Self.rawSql(`
SELECT iit.*,
SUM(iidd.amount) totalDueDay
FROM vn.invoiceIn ii
LEFT JOIN (SELECT SUM(iit.taxableBase) totalTaxableBase,
SUM(iit.taxableBase * (1 + (ti.PorcentajeIva / 100))) totalVat
FROM vn.invoiceInTax iit
LEFT JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk
WHERE iit.invoiceInFk = ?) iit ON TRUE
LEFT JOIN vn.invoiceInDueDay iidd ON iidd.invoiceInFk = ii.id
WHERE
ii.id = ?`, [id, id]))[0];
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -39,13 +39,6 @@ module.exports = Self => {
if (totals.totalDueDay != totals.totalTaxableBase && totals.totalDueDay != totals.totalVal) if (totals.totalDueDay != totals.totalTaxableBase && totals.totalDueDay != totals.totalVal)
throw new UserError(`Amounts do not match`); throw new UserError(`Amounts do not match`);
/* const now = new Date();
const hasFuturePayments = await models.InvoiceInDueDay.findOne({
where: {
invoiceInFk: id,
dueDated: {gte: now}
}
});*/
await Self.rawSql(`CALL vn.invoiceInBookingMain(?)`, [id], myOptions); await Self.rawSql(`CALL vn.invoiceInBookingMain(?)`, [id], myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();
} catch (e) { } catch (e) {

View File

@ -3,19 +3,5 @@ module.exports = Self => {
require('../methods/invoice-in/summary')(Self); require('../methods/invoice-in/summary')(Self);
require('../methods/invoice-in/clone')(Self); require('../methods/invoice-in/clone')(Self);
require('../methods/invoice-in/toBook')(Self); require('../methods/invoice-in/toBook')(Self);
require('../methods/invoice-in/getTotals')(Self);
Self.getTotals = async function getTotals(invoiceInFk) {
return (await Self.rawSql(`
SELECT iit.*,
SUM(iidd.amount) totalDueDay
FROM vn.invoiceIn ii
LEFT JOIN (SELECT SUM(iit.taxableBase) totalTaxableBase,
SUM(iit.taxableBase * (1 + (ti.PorcentajeIva / 100))) totalVat
FROM vn.invoiceInTax iit
LEFT JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk
WHERE iit.invoiceInFk = ?) iit ON TRUE
LEFT JOIN vn.invoiceInDueDay iidd ON iidd.invoiceInFk = ii.id
WHERE
ii.id = ?`, [invoiceInFk, invoiceInFk]))[0];
};
}; };

View File

@ -1,7 +1,7 @@
<vn-descriptor-content module="invoiceIn" description="$ctrl.invoiceIn.supplierRef"> <vn-descriptor-content module="invoiceIn" description="$ctrl.invoiceIn.supplierRef">
<slot-menu> <slot-menu>
<vn-item <vn-item
ng-click="$ctrl.toBook()" ng-click="$ctrl.checktoBook()"
vn-acl="administrative" vn-acl="administrative"
ng-hide="$ctrl.invoiceIn.isBooked == true" ng-hide="$ctrl.invoiceIn.isBooked == true"
translate> translate>
@ -72,3 +72,8 @@
<vn-supplier-descriptor-popover <vn-supplier-descriptor-popover
vn-id="supplierDescriptor"> vn-id="supplierDescriptor">
</vn-supplier-descriptor-popover> </vn-supplier-descriptor-popover>
<vn-confirm
vn-id="confirm-toBookAnyway"
message="???"
on-accept="$ctrl.onAcceptToBook()">
</vn-confirm>

View File

@ -51,9 +51,38 @@ class Controller extends Descriptor {
return this.getData(`InvoiceIns/${this.id}`, {filter}) return this.getData(`InvoiceIns/${this.id}`, {filter})
.then(res => this.entity = res.data); .then(res => this.entity = res.data);
} }
toBook() { checktoBook() {
return this.$http.post(`InvoiceIns/${this.id}/toBook`) let message = '';
.then(() => this.vnApp.showSuccess(this.$t('InvoiceIn booked'))); const id = this.invoiceIn.id;
this.$q.all([
this.$http.get(`InvoiceIns/${this.id}/getTotals`)
.then(res => {
if (res.data.totalDueDay != res.data.totalTaxableBase && res.data.totalDueDay != res.data.totalVat)
message += 'amountsNotMatch';
}),
this.$http.get('InvoiceInDueDays/count', {
filter: {
where: {
invoiceInFk: id,
dueDated: {gte: new Date()}
}
}})
.then(res => {
if (res)
message += 'future payments';
})
]).finally(() => {
if (message > '')
this.$.confirmToBookAnyway.show();
else
onAcceptToBook();
});
}
onAcceptToBook() {
this.$http.post(`InvoiceIns/${this.id}/toBook`);
this.vnApp.showSuccess(this.$t('InvoiceIn booked'));
} }
} }