hotFix #5194 cambios ticketFutureAdvance #1320

Merged
alexandre merged 11 commits from 5194-cambios-ticketFutureAdvance into master 2023-02-16 14:05:44 +00:00
10 changed files with 115 additions and 44 deletions
Showing only changes of commit 8b088e831a - Show all commits

View File

@ -0,0 +1,3 @@
INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`)
VALUES
('Client', 'getClientOrSupplierReference', 'READ', 'ALLOW', 'ROLE', 'employee');

View File

@ -67,7 +67,7 @@ module.exports = function(Self) {
try { try {
delete args.ctx; // Remove unwanted properties delete args.ctx; // Remove unwanted properties
const newReceipt = await models.Receipt.create(args, myOptions);
const originalClient = await models.Client.findById(args.clientFk, null, myOptions); const originalClient = await models.Client.findById(args.clientFk, null, myOptions);
const bank = await models.Bank.findById(args.bankFk, null, myOptions); const bank = await models.Bank.findById(args.bankFk, null, myOptions);
const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions); const accountingType = await models.AccountingType.findById(bank.accountingTypeFk, null, myOptions);
@ -76,23 +76,8 @@ module.exports = function(Self) {
if (!args.compensationAccount) if (!args.compensationAccount)
throw new UserError('Compensation account is empty'); throw new UserError('Compensation account is empty');
const supplierCompensation = await models.Supplier.findOne({ // Check compensation account exists
where: { await models.Client.getClientOrSupplierReference(args.compensationAccount, myOptions);
account: args.compensationAccount
}
}, myOptions);
let clientCompensation = {};
if (!supplierCompensation) {
clientCompensation = await models.Client.findOne({
where: {
accountingAccount: args.compensationAccount
}
}, myOptions);
}
if (!supplierCompensation && !clientCompensation)
throw new UserError('Invalid account');
await Self.rawSql( await Self.rawSql(
`CALL vn.ledger_doCompensation(?, ?, ?, ?, ?, ?, ?)`, `CALL vn.ledger_doCompensation(?, ?, ?, ?, ?, ?, ?)`,
@ -151,7 +136,7 @@ module.exports = function(Self) {
myOptions myOptions
); );
} }
const newReceipt = await models.Receipt.create(args, myOptions);
if (tx) await tx.commit(); if (tx) await tx.commit();
return newReceipt; return newReceipt;

View File

@ -0,0 +1,57 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('getClientOrSupplierReference', {
description: 'Returns the reference of a compensation providing a bank account',
accessType: 'READ',
accepts: {
arg: 'bankAccount',
type: 'number',
required: true,
description: 'The bank account of a client or a supplier'
},
returns: {
type: 'string',
root: true
},
http: {
path: `/getClientOrSupplierReference`,
verb: 'GET'
}
});
Self.getClientOrSupplierReference = async(bankAccount, options) => {
const models = Self.app.models;
const myOptions = {};
let reference = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const supplierCompensation = await models.Supplier.findOne({
where: {
account: bankAccount
}
}, myOptions);
reference.supplierId = supplierCompensation?.id;
reference.supplierName = supplierCompensation?.name;
let clientCompensation = {};
if (!supplierCompensation) {
clientCompensation = await models.Client.findOne({
where: {
accountingAccount: bankAccount
}
}, myOptions);
reference.clientId = clientCompensation?.id;
reference.clientName = clientCompensation?.name;
}
if (!supplierCompensation && !clientCompensation)
throw new UserError('Invalid account');
return reference;
};
};

View File

@ -47,4 +47,5 @@ module.exports = Self => {
require('../methods/client/incotermsAuthorizationEmail')(Self); require('../methods/client/incotermsAuthorizationEmail')(Self);
require('../methods/client/consumptionSendQueued')(Self); require('../methods/client/consumptionSendQueued')(Self);
require('../methods/client/filter')(Self); require('../methods/client/filter')(Self);
require('../methods/client/getClientOrSupplierReference')(Self);
}; };

View File

@ -48,6 +48,14 @@
max="$ctrl.maxAmount"> max="$ctrl.maxAmount">
</vn-input-number> </vn-input-number>
</vn-horizontal> </vn-horizontal>
<vn-vertical ng-show="$ctrl.bankSelection.accountingType.code == 'compensation'">
<h6 translate>Compensation</h6>
<vn-textfield
ng-model="$ctrl.receipt.compensationAccount"
label="Compensation Account"
on-change="$ctrl.accountShortToStandard(value)">
</vn-textfield>
</vn-vertical>
<vn-horizontal> <vn-horizontal>
<vn-textfield <vn-textfield
label="Reference" label="Reference"
@ -71,14 +79,6 @@
</vn-input-number> </vn-input-number>
</vn-horizontal> </vn-horizontal>
</vn-vertical> </vn-vertical>
<vn-vertical ng-show="$ctrl.bankSelection.accountingType.code == 'compensation'">
<h6 translate>Compensation</h6>
<vn-textfield
ng-model="$ctrl.receipt.compensationAccount"
label="Compensation Account"
on-change="$ctrl.accountShortToStandard(value)">
</vn-textfield>
</vn-vertical>
<vn-horizontal ng-show="$ctrl.bankSelection.accountingType.code == 'cash'"> <vn-horizontal ng-show="$ctrl.bankSelection.accountingType.code == 'cash'">
<vn-check <vn-check
label="View receipt" label="View receipt"

View File

@ -60,11 +60,15 @@ class Controller extends Dialog {
const accountingType = value.accountingType; const accountingType = value.accountingType;
this.viewReceipt = accountingType.code == 'cash'; this.viewReceipt = accountingType.code == 'cash';
if (accountingType.code == 'compensation')
this.receipt.description = '';
else {
if (accountingType.receiptDescription != null) { if (accountingType.receiptDescription != null) {
this.receipt.description = accountingType.receiptDescription; this.receipt.description = accountingType.receiptDescription;
if (this.originalDescription) this.receipt.description += `, ${this.originalDescription}`; if (this.originalDescription) this.receipt.description += `, ${this.originalDescription}`;
} else if (this.originalDescription) } else if (this.originalDescription)
this.receipt.description = this.originalDescription; this.receipt.description = this.originalDescription;
}
this.maxAmount = accountingType && accountingType.maxAmount; this.maxAmount = accountingType && accountingType.maxAmount;
this.receipt.payed = new Date(); this.receipt.payed = new Date();
@ -110,7 +114,25 @@ class Controller extends Dialog {
} }
accountShortToStandard(value) { accountShortToStandard(value) {
if (value) {
this.receipt.compensationAccount = value.replace('.', '0'.repeat(11 - value.length)); this.receipt.compensationAccount = value.replace('.', '0'.repeat(11 - value.length));
const params = {bankAccount: this.receipt.compensationAccount};
this.$http.get(`Clients/getClientOrSupplierReference`, {params})
.then(res => {
if (res.data.clientId) {
this.receipt.description = this.$t('Client Compensation Reference', {
clientId: res.data.clientId,
clientName: res.data.clientName
});
} else {
this.receipt.description = this.$t('Supplier Compensation Reference', {
supplierId: res.data.supplierId,
supplierName: res.data.supplierName
});
}
});
} else
this.receipt.description = '';
} }
getAmountPaid() { getAmountPaid() {

View File

@ -1,2 +1,4 @@
View receipt: Ver recibo View receipt: Ver recibo
Amount exceeded: Según ley contra el fraude no se puede recibir cobros por importe igual o superior a {{maxAmount}} Amount exceeded: Según ley contra el fraude no se puede recibir cobros por importe igual o superior a {{maxAmount}}
Client Compensation Reference: "({{clientId}}) Ntro Cliente: {{clientName}}"
Supplier Compensation Reference: "({{supplierId}}) Ntro Proveedor: {{supplierName}}"

View File

@ -17,8 +17,8 @@
</p> </p>
<h4 style="text-align: center; margin-top: 10%">{{$t('Agree') | uppercase}}</h4> <h4 style="text-align: center; margin-top: 10%">{{$t('Agree') | uppercase}}</h4>
<p style="margin-top: 8%; text-align: justify"> <p style="margin-top: 8%; text-align: justify">
{{$t('Date')}} {{formatDate(client.payed, '%d-%m-%Y')}} {{$t('Compensate')}} {{client.amountPaid}} € {{$t('Date')}} {{client.payed | date('%d-%m-%Y')}} {{$t('Compensate')}} {{client.amountPaid}} €
{{$t('From client')}} {{client.name}} {{$t('Toclient')}} {{company.name}}. {{$t('From client')}} {{client.name}} {{$t('Against the balance of')}}: {{client.invoiceFk}}.
</p> </p>
<p style="margin-top: 8%"> <p style="margin-top: 8%">
{{$t('Reception')}} <span style="color: blue">administracion@verdnatura.es</span> {{$t('Reception')}} <span style="color: blue">administracion@verdnatura.es</span>

View File

@ -11,6 +11,6 @@ Agree: Acuerdan
Date: En fecha de Date: En fecha de
Compensate: se ha compensado el saldo de Compensate: se ha compensado el saldo de
From client: del cliente/proveedor From client: del cliente/proveedor
To client: con el cliente/proveedor Against the balance of: contra el saldo de
Reception: Por favor, rogamos confirmen la recepción de esta compensación al email Reception: Por favor, rogamos confirmen la recepción de esta compensación al email
Greetings: Saludos cordiales, Greetings: Saludos cordiales,

View File

@ -4,6 +4,7 @@ SELECT
c.street, c.street,
c.fi, c.fi,
c.city, c.city,
r.invoiceFk,
r.amountPaid, r.amountPaid,
r.payed r.payed
FROM client c FROM client c