5275-item.fixed-price_refactor #1426

Merged
vicent merged 12 commits from 5275-item.fixed-price_refactor into dev 2023-04-11 05:18:53 +00:00
20 changed files with 298 additions and 118 deletions
Showing only changes of commit ba31613ac9 - Show all commits

View File

@ -8,13 +8,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2314.01] - 2023-04-20 ## [2314.01] - 2023-04-20
### Added ### Added
- (Clientes -> Morosos) Ahora se puede filtrar por las columnas "Desde" y "Fecha Ú. O.". También se envia un email al comercial cuando se añade una nota.
- (Monitor tickets) Muestra un icono al lado de la zona, si el ticket es frágil y se envía por agencia
- (Facturas recibidas -> Bases negativas) Nueva sección - (Facturas recibidas -> Bases negativas) Nueva sección
### Changed ### Changed
- -
### Fixed ### Fixed
- - (Clientes -> Morosos) Ahora se mantienen los elementos seleccionados al hacer sroll.
## [2312.01] - 2023-04-06 ## [2312.01] - 2023-04-06

View File

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

View File

@ -0,0 +1,72 @@
DROP TRIGGER IF EXISTS `vn`.`client_beforeUpdate`;
USE `vn`;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`client_beforeUpdate`
BEFORE UPDATE ON `client`
FOR EACH ROW
BEGIN
DECLARE vText VARCHAR(255) DEFAULT NULL;
DECLARE vPayMethodFk INT;
-- Comprueba que el formato de los teléfonos es válido
IF !(NEW.phone <=> OLD.phone) AND (NEW.phone <> '') THEN
CALL pbx.phone_isValid(NEW.phone);
END IF;
IF !(NEW.mobile <=> OLD.mobile) AND (NEW.mobile <> '')THEN
CALL pbx.phone_isValid(NEW.mobile);
END IF;
SELECT id INTO vPayMethodFk
FROM vn.payMethod
WHERE code = 'bankDraft';
IF NEW.payMethodFk = vPayMethodFk AND NEW.dueDay = 0 THEN
SET NEW.dueDay = 5;
END IF;
-- Avisar al comercial si ha llegado la documentación sepa/core
IF NEW.hasSepaVnl AND !OLD.hasSepaVnl THEN
SET vText = 'Sepa de VNL';
END IF;
IF NEW.hasCoreVnl AND !OLD.hasCoreVnl THEN
SET vText = 'Core de VNL';
END IF;
IF vText IS NOT NULL
THEN
INSERT INTO mail(receiver, replyTo, `subject`, body)
SELECT
CONCAT(IF(ac.id,u.name, 'jgallego'), '@verdnatura.es'),
'administracion@verdnatura.es',
CONCAT('Cliente ', NEW.id),
CONCAT('Recibida la documentación: ', vText)
FROM worker w
LEFT JOIN account.user u ON w.userFk = u.id AND u.active
LEFT JOIN account.account ac ON ac.id = u.id
WHERE w.id = NEW.salesPersonFk;
END IF;
IF NEW.salespersonFk IS NULL AND OLD.salespersonFk IS NOT NULL THEN
IF (SELECT COUNT(clientFk)
FROM clientProtected
WHERE clientFk = NEW.id
) > 0 THEN
CALL util.throw("HAS_CLIENT_PROTECTED");
END IF;
END IF;
IF !(NEW.salesPersonFk <=> OLD.salesPersonFk) THEN
SET NEW.lastSalesPersonFk = IFNULL(NEW.salesPersonFk, OLD.salesPersonFk);
END IF;
IF !(NEW.businessTypeFk <=> OLD.businessTypeFk) AND (NEW.businessTypeFk = 'individual' OR OLD.businessTypeFk = 'individual') THEN
SET NEW.isTaxDataChecked = 0;
END IF;
END$$
DELIMITER ;

View File

@ -0,0 +1,13 @@
DROP TRIGGER IF EXISTS `vn`.`invoiceOut_afterInsert`;
USE vn;
DELIMITER $$
$$
CREATE DEFINER=`root`@`localhost` TRIGGER `vn`.`invoiceOut_afterInsert`
AFTER INSERT ON `invoiceOut`
FOR EACH ROW
BEGIN
CALL clientRisk_update(NEW.clientFk, NEW.companyFk, NEW.amount);
END$$
DELIMITER ;

View File

@ -268,9 +268,11 @@
"Exists an invoice with a previous date": "Existe una factura con fecha anterior", "Exists an invoice with a previous date": "Existe una factura con fecha anterior",
"Invoice date can't be less than max date": "La fecha de factura no puede ser inferior a la fecha límite", "Invoice date can't be less than max date": "La fecha de factura no puede ser inferior a la fecha límite",
"Warehouse inventory not set": "El almacén inventario no está establecido", "Warehouse inventory not set": "El almacén inventario no está establecido",
"This locker has already been assigned": "Esta taquilla ya ha sido asignada", "This locker has already been assigned": "Esta taquilla ya ha sido asignada",
"Tickets with associated refunds": "No se pueden borrar tickets con abonos asociados. Este ticket está asociado al abono Nº {{id}}", "Tickets with associated refunds": "No se pueden borrar tickets con abonos asociados. Este ticket está asociado al abono Nº {{id}}",
"Not exist this branch": "La rama no existe", "Not exist this branch": "La rama no existe",
"This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado", "This ticket cannot be signed because it has not been boxed": "Este ticket no puede firmarse porque no ha sido encajado",
"Insert a date range": "Inserte un rango de fechas" "Insert a date range": "Inserte un rango de fechas",
"Added observation": "{{user}} añadió esta observacion: {{text}}",
"Comment added to client": "Observación añadida al cliente {{clientFk}}"
} }

View File

@ -1,63 +0,0 @@
module.exports = Self => {
Self.remoteMethod('checkDuplicatedData', {
description: 'Checks if a client has same email, mobile or phone than other client and send an email',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The client id'
}],
returns: {
type: 'object',
root: true
},
http: {
verb: 'GET',
path: '/:id/checkDuplicatedData'
}
});
Self.checkDuplicatedData = async function(id, options) {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const client = await Self.app.models.Client.findById(id, myOptions);
const findParams = [];
if (client.email) {
const emails = client.email.split(',');
for (let email of emails)
findParams.push({email: email});
}
if (client.phone)
findParams.push({phone: client.phone});
if (client.mobile)
findParams.push({mobile: client.mobile});
const filterObj = {
where: {
and: [
{or: findParams},
{id: {neq: client.id}}
]
}
};
const clientSameData = await Self.findOne(filterObj, myOptions);
if (clientSameData) {
await Self.app.models.Mail.create({
receiver: 'direccioncomercial@verdnatura.es',
subject: `Cliente con email/teléfono/móvil duplicados`,
body: 'El cliente ' + client.id + ' comparte alguno de estos datos con el cliente ' + clientSameData.id +
'\n- Email: ' + client.email +
'\n- Teléfono: ' + client.phone +
'\n- Móvil: ' + client.mobile
}, myOptions);
}
};
};

View File

@ -1,24 +0,0 @@
const models = require('vn-loopback/server/server').models;
describe('client checkDuplicated()', () => {
it('should send an mail if mobile/phone/email is duplicated', async() => {
const tx = await models.Client.beginTransaction({});
try {
const options = {transaction: tx};
const id = 1110;
const mailModel = models.Mail;
spyOn(mailModel, 'create');
await models.Client.checkDuplicatedData(id, options);
expect(mailModel.create).toHaveBeenCalled();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -0,0 +1,52 @@
module.exports = Self => {
Self.remoteMethodCtx('observationEmail', {
description: 'Send an email with the observation',
accessType: 'WRITE',
accepts: [
{
arg: 'defaulters',
type: ['object'],
required: true,
description: 'The defaulters to send the email'
},
{
arg: 'observation',
type: 'string',
required: true,
description: 'The observation'
}],
returns: {
arg: 'observationEmail'
},
http: {
path: `/observationEmail`,
verb: 'POST'
}
});
Self.observationEmail = async(ctx, defaulters, observation, options) => {
const models = Self.app.models;
const $t = ctx.req.__; // $translate
const myOptions = {};
const userId = ctx.req.accessToken.userId;
if (typeof options == 'object')
Object.assign(myOptions, options);
for (const defaulter of defaulters) {
const user = await models.Account.findById(userId, {fields: ['name']}, myOptions);
const body = $t('Added observation', {
user: user.name,
text: observation
});
await models.Mail.create({
subject: $t('Comment added to client', {clientFk: defaulter.clientFk}),
body: body,
receiver: `${defaulter.salesPersonName}@verdnatura.es`,
replyTo: `${user.name}@verdnatura.es`
}, myOptions);
}
};
};

View File

@ -2,7 +2,6 @@ module.exports = Self => {
require('../methods/client/addressesPropagateRe')(Self); require('../methods/client/addressesPropagateRe')(Self);
require('../methods/client/canBeInvoiced')(Self); require('../methods/client/canBeInvoiced')(Self);
require('../methods/client/canCreateTicket')(Self); require('../methods/client/canCreateTicket')(Self);
require('../methods/client/checkDuplicated')(Self);
require('../methods/client/confirmTransaction')(Self); require('../methods/client/confirmTransaction')(Self);
require('../methods/client/consumption')(Self); require('../methods/client/consumption')(Self);
require('../methods/client/createAddress')(Self); require('../methods/client/createAddress')(Self);

View File

@ -1,3 +1,4 @@
module.exports = Self => { module.exports = Self => {
require('../methods/defaulter/filter')(Self); require('../methods/defaulter/filter')(Self);
require('../methods/defaulter/observationEmail')(Self);
}; };

View File

@ -9,9 +9,7 @@ export default class Controller extends Section {
} }
onSubmit() { onSubmit() {
return this.$.watcher.submit().then(() => { return this.$.watcher.submit();
this.$http.get(`Clients/${this.$params.id}/checkDuplicatedData`);
});
} }
} }

View File

@ -12,7 +12,6 @@ export default class Controller extends Section {
onSubmit() { onSubmit() {
return this.$.watcher.submit().then(json => { return this.$.watcher.submit().then(json => {
this.$state.go('client.card.basicData', {id: json.data.id}); this.$state.go('client.card.basicData', {id: json.data.id});
this.$http.get(`Clients/${this.client.id}/checkDuplicatedData`);
}); });
} }

View File

@ -5,6 +5,7 @@
limit="20" limit="20"
order="amount DESC" order="amount DESC"
data="defaulters" data="defaulters"
on-data-change="$ctrl.reCheck()"
auto-load="true"> auto-load="true">
</vn-crud-model> </vn-crud-model>
<vn-portal slot="topbar"> <vn-portal slot="topbar">
@ -90,6 +91,7 @@
<td shrink> <td shrink>
<vn-check <vn-check
ng-model="defaulter.checked" ng-model="defaulter.checked"
on-change="$ctrl.saveChecked(defaulter.clientFk)"
vn-click-stop> vn-click-stop>
</vn-check> </vn-check>
</td> </td>

View File

@ -6,6 +6,7 @@ export default class Controller extends Section {
constructor($element, $) { constructor($element, $) {
super($element, $); super($element, $);
this.defaulter = {}; this.defaulter = {};
this.checkedDefaulers = [];
this.smartTableOptions = { this.smartTableOptions = {
activeButtons: { activeButtons: {
@ -45,11 +46,11 @@ export default class Controller extends Section {
}, },
{ {
field: 'created', field: 'created',
searchable: false datepicker: true
}, },
{ {
field: 'defaulterSinced', field: 'defaulterSinced',
searchable: false datepicker: true
} }
] ]
}; };
@ -68,6 +69,19 @@ export default class Controller extends Section {
return checkedLines; return checkedLines;
} }
saveChecked(clientId) {
this.checkedDefaulers = this.checkedDefaulers.includes(clientId) ?
this.checkedDefaulers.filter(id => id !== clientId) : [...this.checkedDefaulers, clientId];
}
reCheck() {
if (!this.$.model.data || !this.checkedDefaulers.length) return;
this.$.model.data.forEach(defaulter => {
defaulter.checked = this.checkedDefaulers.includes(defaulter.clientFk);
});
}
getBalanceDueTotal() { getBalanceDueTotal() {
this.$http.get('Defaulters/filter') this.$http.get('Defaulters/filter')
.then(res => { .then(res => {
@ -109,11 +123,20 @@ export default class Controller extends Section {
} }
this.$http.post(`ClientObservations`, params) .then(() => { this.$http.post(`ClientObservations`, params) .then(() => {
this.vnApp.showMessage(this.$t('Observation saved!')); this.vnApp.showSuccess(this.$t('Observation saved!'));
this.sendMail();
this.$state.reload(); this.$state.reload();
}); });
} }
sendMail() {
const params = {
defaulters: this.checked,
observation: this.defaulter.observation
};
this.$http.post(`Defaulters/observationEmail`, params);
}
exprBuilder(param, value) { exprBuilder(param, value) {
switch (param) { switch (param) {
case 'creditInsurance': case 'creditInsurance':
@ -122,8 +145,25 @@ export default class Controller extends Section {
case 'workerFk': case 'workerFk':
case 'salesPersonFk': case 'salesPersonFk':
return {[`d.${param}`]: value}; return {[`d.${param}`]: value};
case 'created':
return {'d.created': {
between: this.dateRange(value)}
};
case 'defaulterSinced':
return {'d.defaulterSinced': {
between: this.dateRange(value)}
};
} }
} }
dateRange(value) {
const minHour = new Date(value);
minHour.setHours(0, 0, 0, 0);
const maxHour = new Date(value);
maxHour.setHours(23, 59, 59, 59);
return [minHour, maxHour];
}
} }
ngModule.vnComponent('vnClientDefaulter', { ngModule.vnComponent('vnClientDefaulter', {

View File

@ -81,14 +81,15 @@ describe('client defaulter', () => {
const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}]; const params = [{text: controller.defaulter.observation, clientFk: data[1].clientFk}];
jest.spyOn(controller.vnApp, 'showMessage'); jest.spyOn(controller.vnApp, 'showSuccess');
$httpBackend.expect('GET', `Defaulters/filter`).respond(200); $httpBackend.expect('GET', `Defaulters/filter`).respond(200);
$httpBackend.expect('POST', `ClientObservations`, params).respond(200, params); $httpBackend.expect('POST', `ClientObservations`, params).respond(200, params);
$httpBackend.expect('POST', `Defaulters/observationEmail`).respond(200);
controller.onResponse(); controller.onResponse();
$httpBackend.flush(); $httpBackend.flush();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Observation saved!'); expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Observation saved!');
}); });
}); });
@ -117,5 +118,62 @@ describe('client defaulter', () => {
expect(controller.balanceDueTotal).toEqual(875); expect(controller.balanceDueTotal).toEqual(875);
}); });
}); });
describe('dateRange()', () => {
it('should return two dates with the hours at the start and end of the given date', () => {
const now = Date.vnNew();
const today = now.getDate();
const dateRange = controller.dateRange(now);
const start = dateRange[0].toString();
const end = dateRange[1].toString();
expect(start).toContain(today);
expect(start).toContain('00:00:00');
expect(end).toContain(today);
expect(end).toContain('23:59:59');
});
});
describe('reCheck()', () => {
it(`should recheck buys`, () => {
controller.$.model.data = [
{checked: false, clientFk: 1},
{checked: false, clientFk: 2},
{checked: false, clientFk: 3},
{checked: false, clientFk: 4},
];
controller.checkedDefaulers = [1, 2];
controller.reCheck();
expect(controller.$.model.data[0].checked).toEqual(true);
expect(controller.$.model.data[1].checked).toEqual(true);
expect(controller.$.model.data[2].checked).toEqual(false);
expect(controller.$.model.data[3].checked).toEqual(false);
});
});
describe('saveChecked()', () => {
it(`should check buy`, () => {
const buyCheck = 3;
controller.checkedDefaulers = [1, 2];
controller.saveChecked(buyCheck);
expect(controller.checkedDefaulers[2]).toEqual(buyCheck);
});
it(`should uncheck buy`, () => {
const buyUncheck = 3;
controller.checkedDefaulers = [1, 2, 3];
controller.saveChecked(buyUncheck);
expect(controller.checkedDefaulers[2]).toEqual(undefined);
});
});
}); });
}); });

View File

@ -7,3 +7,5 @@ L. O. Date: Fecha Ú. O.
Last observation date: Fecha última observación Last observation date: Fecha última observación
Search client: Buscar clientes Search client: Buscar clientes
Worker who made the last observation: Trabajador que ha realizado la última observación Worker who made the last observation: Trabajador que ha realizado la última observación
Email sended!: Email enviado!
Observation saved!: Observación añadida!

View File

@ -2,6 +2,10 @@ import ngModule from '../module';
import Section from 'salix/components/section'; import Section from 'salix/components/section';
export default class Controller extends Section { export default class Controller extends Section {
$onInit() {
this.card.reload();
}
onSubmit() { onSubmit() {
const orgData = this.$.watcher.orgData; const orgData = this.$.watcher.orgData;
delete this.client.despiteOfClient; delete this.client.despiteOfClient;

View File

@ -38,6 +38,19 @@
url="Warehouses"> url="Warehouses">
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal class="vn-px-lg">
<vn-autocomplete
vn-one
ng-model="filter.requesterFk"
url="Workers/activeWithRole"
search-function="{firstName: $search}"
value-field="id"
where="{role: 'salesPerson'}"
label="Comercial">
<tpl-item>{{firstName}} {{lastName}}</tpl-item>
</vn-autocomplete>
</vn-horizontal>
<section class="vn-px-md"> <section class="vn-px-md">
<vn-horizontal class="manifold-panel vn-pa-md"> <vn-horizontal class="manifold-panel vn-pa-md">
<vn-date-picker <vn-date-picker

View File

@ -6,3 +6,4 @@ Route Price: Precio ruta
Minimum Km: Km minimos Minimum Km: Km minimos
Remove row: Eliminar fila Remove row: Eliminar fila
Add row: Añadir fila Add row: Añadir fila
New autonomous: Nuevo autónomo

View File

@ -37,6 +37,10 @@ module.exports = Self => {
type: 'number', type: 'number',
description: `Search requests attended by a given worker id` description: `Search requests attended by a given worker id`
}, },
{
arg: 'requesterFk',
type: 'number'
},
{ {
arg: 'mine', arg: 'mine',
type: 'boolean', type: 'boolean',
@ -89,6 +93,8 @@ module.exports = Self => {
return {'t.id': value}; return {'t.id': value};
case 'attenderFk': case 'attenderFk':
return {'tr.attenderFk': value}; return {'tr.attenderFk': value};
case 'requesterFk':
return {'tr.requesterFk': value};
case 'state': case 'state':
switch (value) { switch (value) {
case 'pending': case 'pending':
@ -125,6 +131,7 @@ module.exports = Self => {
tr.description, tr.description,
tr.response, tr.response,
tr.saleFk, tr.saleFk,
tr.requesterFk,
tr.isOk, tr.isOk,
s.quantity AS saleQuantity, s.quantity AS saleQuantity,
s.itemFk, s.itemFk,