2883-invoiceIn-Booking #786

Merged
carlosjr merged 17 commits from 2883-invoiceIn-Booking into dev 2022-01-24 15:29:57 +00:00
6 changed files with 93 additions and 26 deletions
Showing only changes of commit 4f1fd5412d - Show all commits

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) {
jgallego marked this conversation as resolved
Review

creating transaction on a read methods is required.

creating transaction on a read methods is required.
Review

is not* required

is not* required
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
return (await Self.rawSql(`
jgallego marked this conversation as resolved
Review

It is easier for code maintenance to extract values to constants or variables

It is easier for code maintenance to extract values to constants or variables
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
jgallego marked this conversation as resolved Outdated

remove the ()

remove the ()
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();
jgallego marked this conversation as resolved Outdated

endpoints that don't create transactions should not attempt to rollback.

(also the commit was missing)

endpoints that don't create transactions should not attempt to rollback. (also the commit was missing)
throw e;
}
};
};

View File

@ -39,13 +39,6 @@ module.exports = Self => {
if (totals.totalDueDay != totals.totalTaxableBase && totals.totalDueDay != totals.totalVal)
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);
if (tx) await tx.commit();
} catch (e) {

View File

@ -3,19 +3,5 @@ module.exports = Self => {
require('../methods/invoice-in/summary')(Self);
require('../methods/invoice-in/clone')(Self);
require('../methods/invoice-in/toBook')(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];
};
require('../methods/invoice-in/getTotals')(Self);
};

View File

@ -1,7 +1,7 @@
<vn-descriptor-content module="invoiceIn" description="$ctrl.invoiceIn.supplierRef">
<slot-menu>
<vn-item
ng-click="$ctrl.toBook()"
ng-click="$ctrl.checktoBook()"
vn-acl="administrative"
ng-hide="$ctrl.invoiceIn.isBooked == true"
translate>
@ -72,3 +72,8 @@
<vn-supplier-descriptor-popover
vn-id="supplierDescriptor">
</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})
.then(res => this.entity = res.data);
}
toBook() {
return this.$http.post(`InvoiceIns/${this.id}/toBook`)
.then(() => this.vnApp.showSuccess(this.$t('InvoiceIn booked')));
checktoBook() {
let message = '';
jgallego marked this conversation as resolved Outdated

function naming must be in lowerCamelCase

function naming must be in lowerCamelCase
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'));
}
}